DbConnection DbConnection DbConnection DbConnection Class

定义

表示到数据库的连接。Represents a connection to a database.

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继承时, 必须重写以下成员: 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. 还必须提供以下属性: ConnectionStringDatabaseDataSourceServerVersionStateYou must also provide the following properties: ConnectionString, Database, DataSource, ServerVersion, and State.

构造函数

DbConnection() DbConnection() DbConnection() DbConnection()

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

属性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

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

(Inherited from Component)
ConnectionString ConnectionString ConnectionString ConnectionString

获取或设置用于打开连接的字符串。Gets or sets the string used to open the connection.

ConnectionTimeout ConnectionTimeout ConnectionTimeout ConnectionTimeout

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

Container Container Container Container

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

(Inherited from Component)
Database Database Database Database

在连接打开之后获取当前数据库的名称,或者在连接打开之前获取连接字符串中指定的数据库名。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 DataSource DataSource DataSource

获取要连接的数据库服务器的名称。Gets the name of the database server to which to connect.

DbProviderFactory DbProviderFactory DbProviderFactory DbProviderFactory

获取此 DbProviderFactoryDbConnectionGets the DbProviderFactory for this DbConnection.

DesignMode DesignMode DesignMode DesignMode

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

(Inherited from Component)
Events Events Events Events

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

(Inherited from Component)
ServerVersion ServerVersion ServerVersion ServerVersion

获取表示对象所连接到的服务器的版本的字符串。Gets a string that represents the version of the server to which the object is connected.

Site Site Site Site

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

(Inherited from Component)
State State State State

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

方法

BeginDbTransaction(IsolationLevel) BeginDbTransaction(IsolationLevel) BeginDbTransaction(IsolationLevel) BeginDbTransaction(IsolationLevel)

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

BeginDbTransactionAsync(IsolationLevel, CancellationToken) BeginDbTransactionAsync(IsolationLevel, CancellationToken) BeginDbTransactionAsync(IsolationLevel, CancellationToken) BeginDbTransactionAsync(IsolationLevel, CancellationToken)
BeginTransaction() BeginTransaction() BeginTransaction() BeginTransaction()

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

BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel)

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

BeginTransactionAsync(CancellationToken) BeginTransactionAsync(CancellationToken) BeginTransactionAsync(CancellationToken) BeginTransactionAsync(CancellationToken)
BeginTransactionAsync(IsolationLevel, CancellationToken) BeginTransactionAsync(IsolationLevel, CancellationToken) BeginTransactionAsync(IsolationLevel, CancellationToken) BeginTransactionAsync(IsolationLevel, CancellationToken)
ChangeDatabase(String) ChangeDatabase(String) ChangeDatabase(String) ChangeDatabase(String)

为打开的连接更改当前数据库。Changes the current database for an open connection.

ChangeDatabaseAsync(String, CancellationToken) ChangeDatabaseAsync(String, CancellationToken) ChangeDatabaseAsync(String, CancellationToken) ChangeDatabaseAsync(String, CancellationToken)
Close() Close() Close() Close()

关闭与数据库之间的连接。Closes the connection to the database. 此方法是关闭任何打开连接的首选方法。This is the preferred method of closing any open connection.

CloseAsync() CloseAsync() CloseAsync() CloseAsync()
CreateCommand() CreateCommand() CreateCommand() CreateCommand()

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

CreateDbCommand() CreateDbCommand() CreateDbCommand() CreateDbCommand()

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

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

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

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)
DisposeAsync() DisposeAsync() DisposeAsync() DisposeAsync()
EnlistTransaction(Transaction) EnlistTransaction(Transaction) EnlistTransaction(Transaction) EnlistTransaction(Transaction)

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetSchema() GetSchema() GetSchema() GetSchema()

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

GetSchema(String) GetSchema(String) GetSchema(String) GetSchema(String)

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

GetSchema(String, String[]) GetSchema(String, String[]) GetSchema(String, String[]) 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) GetService(Type) GetService(Type) GetService(Type)

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

(Inherited from Component)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
OnStateChange(StateChangeEventArgs) OnStateChange(StateChangeEventArgs) OnStateChange(StateChangeEventArgs) OnStateChange(StateChangeEventArgs)

引发 StateChange 事件。Raises the StateChange event.

Open() Open() Open() Open()

使用 ConnectionString 所指定的设置打开数据库连接。Opens a database connection with the settings specified by the ConnectionString.

OpenAsync() OpenAsync() OpenAsync() 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) OpenAsync(CancellationToken) OpenAsync(CancellationToken) 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() ToString() ToString() ToString()

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

(Inherited from Component)

事件

Disposed Disposed Disposed Disposed

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

(Inherited from Component)
StateChange StateChange StateChange StateChange

当事件状态更改时发生。Occurs when the state of the event changes.

显式界面实现

IDbConnection.BeginTransaction() IDbConnection.BeginTransaction() IDbConnection.BeginTransaction() IDbConnection.BeginTransaction()

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

IDbConnection.BeginTransaction(IsolationLevel) IDbConnection.BeginTransaction(IsolationLevel) IDbConnection.BeginTransaction(IsolationLevel) IDbConnection.BeginTransaction(IsolationLevel)

以指定的 IsolationLevel 值开始数据库事务。Begins a database transaction with the specified IsolationLevel value.

IDbConnection.CreateCommand() IDbConnection.CreateCommand() IDbConnection.CreateCommand() IDbConnection.CreateCommand()

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

适用于

另请参阅