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 繼承時,必須覆寫下列成員: 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 類別的新執行個體。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

取得包含 IContainerComponentGets 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

取得或設定 ComponentISiteGets 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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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 的淺層複本 (Shallow Copy)。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. 這個方法會叫用虛擬方法 OpenAsync(CancellationToken) 與 CancellationToken.None。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()

傳回任何包含 Component 名稱的 StringReturns 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 event 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.

適用於

另請參閱