DbConnection.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) |
這是 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. 在傳回的工作完成之前,不叫用 |
備註
如需有關 SQL Server 之 .NET Framework Data Provider 中非同步程式設計的詳細資訊,請參閱 非同步程式設計。For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.
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.
public:
System::Threading::Tasks::Task ^ OpenAsync();
public System.Threading.Tasks.Task OpenAsync ();
member this.OpenAsync : unit -> System.Threading.Tasks.Task
Public Function OpenAsync () As Task
傳回
表示非同步作業的工作。A task representing the asynchronous operation.
備註
在呼叫之後 OpenAsync , State 必須 Connecting 等到傳回的 Task 完成後才會返回。After calling OpenAsync, State must return Connecting until the returned Task is completed. 然後,如果連接成功,則 State 必須傳回 Open 。Then, if the connection was successful, State must return Open. 如果連接失敗,則 State 必須傳回 Closed 。If the connection fails, State must return Closed.
的呼叫 Close 會嘗試取消或關閉對應的 OpenAsync 呼叫。A call to Close will attempt to cancel or close the corresponding OpenAsync call.
如需有關 SQL Server 之 .NET Framework Data Provider 中非同步程式設計的詳細資訊,請參閱 非同步程式設計。For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.
另請參閱
適用於
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.
public:
virtual System::Threading::Tasks::Task ^ OpenAsync(System::Threading::CancellationToken cancellationToken);
public virtual System.Threading.Tasks.Task OpenAsync (System.Threading.CancellationToken cancellationToken);
abstract member OpenAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.OpenAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overridable Function OpenAsync (cancellationToken As CancellationToken) As Task
參數
- cancellationToken
- CancellationToken
取消指令。The cancellation instruction.
傳回
表示非同步作業的工作。A task representing the asynchronous operation.
備註
在呼叫之後 OpenAsync , State 必須 Connecting 等到傳回的 Task 完成後才會返回。After calling OpenAsync, State must return Connecting until the returned Task is completed. 然後,如果連接成功,則 State 必須傳回 Open 。Then, if the connection was successful, State must return Open. 如果連接失敗,則 State 必須傳回 Closed 。If the connection fails, State must return Closed.
的呼叫 Close 會嘗試取消或關閉對應的 OpenAsync 呼叫。A call to Close will attempt to cancel or close the corresponding OpenAsync call.
如需有關 SQL Server 之 .NET Framework Data Provider 中非同步程式設計的詳細資訊,請參閱 非同步程式設計。For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.