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. 您也必須提供下列屬性: ConnectionStringDatabaseDataSourceServerVersion,和StateYou 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

取得包含 IContainerComponentGets 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(CancellationToken) CloseAsync(CancellationToken) CloseAsync(CancellationToken) CloseAsync(CancellationToken)
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)

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

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

適用於

另請參閱