Uredi

Deli z drugimi prek


DbDataSource.OpenConnectionAsync(CancellationToken) Method

Definition

Asynchronously returns a new, open connection to the database represented by this DbDataSource.

public System.Threading.Tasks.ValueTask<System.Data.Common.DbConnection> OpenConnectionAsync (System.Threading.CancellationToken cancellationToken = default);
member this.OpenConnectionAsync : System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<System.Data.Common.DbConnection>
Public Function OpenConnectionAsync (Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of DbConnection)

Parameters

cancellationToken
CancellationToken

A token to cancel the asynchronous operation.

Returns

A new, open connection to the database represented by this DbDataSource.

Exceptions

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

Remarks

The returned connection is already open, and is ready for immediate use.

It is the responsibility of the caller to properly dispose the connection returned by this method. Failure to do so may result in a connection leak.

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

Applies to