Επεξεργασία

Κοινή χρήση μέσω


DbConnection.OpenAsync Method

Definition

This method implements an asynchronous version of Open().

Overloads

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)

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()

Source:
DbConnection.cs
Source:
DbConnection.cs
Source:
DbConnection.cs

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.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Open().

See also

Applies to

OpenAsync(CancellationToken)

Source:
DbConnection.cs
Source:
DbConnection.cs
Source:
DbConnection.cs

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
Public Overridable Function OpenAsync (cancellationToken As CancellationToken) As Task

Parameters

cancellationToken
CancellationToken

The cancellation instruction.

Returns

A task representing the asynchronous operation.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

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.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Open().

See also

Applies to