DbConnection.OpenAsync DbConnection.OpenAsync DbConnection.OpenAsync DbConnection.OpenAsync Method

Definition

This method implements an asynchronous version of Open().

Overloads

OpenAsync() OpenAsync() OpenAsync() OpenAsync()

An asynchronous version of Open(), which opens a database connection with the settings specified by the ConnectionString. This method invokes the virtual method OpenAsync(CancellationToken) with CancellationToken.None.

OpenAsync(CancellationToken) OpenAsync(CancellationToken) OpenAsync(CancellationToken)

This is the asynchronous version of Open(). Providers should override with an appropriate implementation. The cancellation token can optionally be honored.

The default implementation invokes the synchronous Open() call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by Open will be communicated via the returned Task Exception property.

Do not invoke other methods and properties of the DbConnection object until the returned Task is complete.

Remarks

For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.

OpenAsync() OpenAsync() OpenAsync() OpenAsync()

An asynchronous version of Open(), which opens a database connection with the settings specified by the ConnectionString. 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
Returns

A task representing the asynchronous operation.

Remarks

After calling OpenAsync, State must return Connecting until the returned Task is completed. Then, if the connection was successful, State must return Open. If the connection fails, State must return Closed.

A call to Close will attempt to cancel or close the corresponding OpenAsync call.

For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.

OpenAsync(CancellationToken) OpenAsync(CancellationToken) OpenAsync(CancellationToken)

This is the asynchronous version of Open(). Providers should override with an appropriate implementation. The cancellation token can optionally be honored.

The default implementation invokes the synchronous Open() call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by Open will be communicated via the returned Task Exception property.

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
Parameters
cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

The cancellation instruction.

Returns

A task representing the asynchronous operation.

Remarks

After calling OpenAsync, State must return Connecting until the returned Task is completed. Then, if the connection was successful, State must return Open. If the connection fails, State must return Closed.

A call to Close will attempt to cancel or close the corresponding OpenAsync call.

For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.

Applies to