DbConnection 类

定义

定义数据库连接的核心行为,并为数据库专用连接提供基类。Defines the core behavior of database connections and provides a base class for database-specific connections.

public ref class DbConnection abstract : System::ComponentModel::Component, IDisposable, System::Data::IDbConnection
public abstract class DbConnection : System.ComponentModel.Component, IDisposable, System.Data.IDbConnection
type DbConnection = class
    inherit Component
    interface IDbConnection
    interface IDisposable
Public MustInherit Class DbConnection
Inherits Component
Implements IDbConnection, IDisposable
继承
DbConnection
继承
派生
实现

实施者说明

DbConnection继承时,必须重写以下成员: Close()BeginDbTransaction(IsolationLevel)ChangeDatabase(String)CreateDbCommand()Open()StateChangeWhen you inherit from DbConnection, you must override the following members: Close(), BeginDbTransaction(IsolationLevel), ChangeDatabase(String), CreateDbCommand(), Open(), and StateChange. 还必须提供以下属性: "ConnectionString"、"Database"、"DataSource"、"ServerVersion" 和 "State"。You must also provide the following properties: ConnectionString, Database, DataSource, ServerVersion, and State.

构造函数

DbConnection()

初始化 DbConnection 类的新实例。Initializes a new instance of the DbConnection class.

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
ConnectionString

在派生类中重写时,获取或设置用于打开连接的字符串。When overridden in a derived class, gets or sets the string used to open the connection.

ConnectionTimeout

获取在建立连接时终止尝试并生成错误之前所等待的时间(以秒为单位)。Gets the time to wait (in seconds) while establishing a connection before terminating the attempt and generating an error.

Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
Database

在派生类中重写时,在连接打开之后获取当前数据库的名称,或者在连接打开之前获取连接字符串中指定的数据库名。When overridden in a derived class, gets the name of the current database after a connection is opened, or the database name specified in the connection string before the connection is opened.

DataSource

在派生类中重写时,获取要连接的数据库服务器的名称。When overridden in a derived class, gets the name of the database server to which to connect.

DbProviderFactory

获取此 DbProviderFactoryDbConnectionGets the DbProviderFactory for this DbConnection.

DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
ServerVersion

在派生类中重写时,获取表示对象所连接到的服务器的版本的字符串。When overridden in a derived class, gets a string that represents the version of the server to which the object is connected.

Site

获取或设置 ISiteComponentGets or sets the ISite of the Component.

(继承自 Component)
State

获取描述连接状态的字符串。Gets a string that describes the state of the connection.

方法

BeginDbTransaction(IsolationLevel)

在派生类中重写时,启动数据库事务。When overridden in a derived class, starts a database transaction.

BeginDbTransactionAsync(IsolationLevel, CancellationToken)

异步启动数据库事务。Asynchronously starts a database transaction.

BeginTransaction()

开始数据库事务。Starts a database transaction.

BeginTransaction(IsolationLevel)

以指定的隔离级别启动数据库事务。Starts a database transaction with the specified isolation level.

BeginTransactionAsync(CancellationToken)

异步开始数据库事务。Asynchronously begins a database transaction.

BeginTransactionAsync(IsolationLevel, CancellationToken)

异步开始数据库事务。Asynchronously begins a database transaction.

ChangeDatabase(String)

当在派生类中重写时,更改打开的连接的当前数据库。When overridden in a derived class, changes the current database for an open connection.

ChangeDatabaseAsync(String, CancellationToken)

为打开的连接对象异步更改当前数据库。Asynchronously changes the current database for an open connection.

Close()

在派生类中重写时,关闭与数据库之间的连接。When overridden in a derived class, closes the connection to the database.

CloseAsync()

异步关闭与数据库之间的连接。Asynchronously closes the connection to the database.

CreateCommand()

创建并返回与当前连接关联的 DbCommand 对象。Creates and returns a DbCommand object associated with the current connection.

CreateDbCommand()

在派生类中重写时,创建并返回与当前连接关联的 DbCommand 对象。When overridden in a derived class, creates and returns a DbCommand object associated with the current connection.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()
Dispose(Boolean)
DisposeAsync()

异步处置连接对象。Asynchronously diposes the connection object.

EnlistTransaction(Transaction)

在指定事务中登记。Enlists in the specified transaction.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetSchema()

返回此 DbConnection 的数据源的架构信息。Returns schema information for the data source of this DbConnection.

GetSchema(String)

通过使用架构名称的指定字符串,返回此 DbConnection 的数据源的架构信息。Returns schema information for the data source of this DbConnection using the specified string for the schema name.

GetSchema(String, String[])

通过使用指定字符串作为架构名称,指定字符串数组作为限制值,返回此 DbConnection 的数据源的架构信息。Returns schema information for the data source of this DbConnection using the specified string for the schema name and the specified string array for the restriction values.

GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
OnStateChange(StateChangeEventArgs)

引发 StateChange 事件。Raises the StateChange event.

Open()

在派生类中重写时,打开其设置由 ConnectionString 指定的数据库连接。When overridden in a derived class, opens a database connection with the settings specified by the ConnectionString.

OpenAsync()

Open()的异步版本,打开由 ConnectionString指定的设置的数据库连接。An asynchronous version of Open(), which opens a database connection with the settings specified by the ConnectionString. 此方法通过 CancellationToken.None 调用虚拟方法 OpenAsync(CancellationToken)This method invokes the virtual method OpenAsync(CancellationToken) with CancellationToken.None.

OpenAsync(CancellationToken)

这是 Open() 的异步版本。This is the asynchronous version of Open(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性接受取消标记。The cancellation token can optionally be honored.

默认实现调用同步 Open() 调用并返回已完成任务。The default implementation invokes the synchronous Open() call and returns a completed task. 如果传递到已取消的取消标记,则默认实现将返回已取消的 cancellationToken。The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Open 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by Open will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbConnection 对象的其他方法和属性。Do not invoke other methods and properties of the DbConnection object until the returned Task is complete.

ToString()

返回包含 String 的名称的 Component(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)

事件

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)
StateChange

当连接状态改变时发生。Occurs when the state of the connection changes.

显式接口实现

IDbConnection.BeginTransaction()

开始一项数据库事务。Begins a database transaction.

IDbConnection.BeginTransaction(IsolationLevel)

以指定的隔离级别启动数据库事务。Begins a database transaction with the specified isolation level.

IDbConnection.CreateCommand()

创建并返回与当前连接关联的 DbCommand 对象。Creates and returns a DbCommand object that is associated with the current connection.

适用于

另请参阅