Table of Contents

Class AsyncDbConnection

Namespace
LinqToDB.Async
Assembly
linq2db.dll

Implements IAsyncDbConnection wrapper over DbConnection instance with synchronous implementation of asynchronous methods. Providers with async operations support could override its methods with asynchronous implementations.

public class AsyncDbConnection : IAsyncDbConnection, IDisposable, IAsyncDisposable
Inheritance
AsyncDbConnection
Implements
Extension Methods

Constructors

AsyncDbConnection(DbConnection)

protected AsyncDbConnection(DbConnection connection)

Parameters

connection DbConnection

Properties

Connection

Gets underlying connection instance.

public virtual DbConnection Connection { get; }

Property Value

DbConnection

ConnectionString

Gets or sets the string used to open the connection.

public virtual string ConnectionString { get; set; }

Property Value

string

The connection string used to establish the initial connection. The exact contents of the connection string depend on the specific data source for this connection. The default value is an empty string.

State

Gets a string that describes the state of the connection.

public virtual ConnectionState State { get; }

Property Value

ConnectionState

The state of the connection. The format of the string returned depends on the specific type of connection you are using.

Methods

BeginTransaction()

Starts new transaction for current connection with default isolation level.

public virtual IAsyncDbTransaction BeginTransaction()

Returns

IAsyncDbTransaction

Database transaction object.

BeginTransaction(IsolationLevel)

Starts new transaction for current connection with specified isolation level.

public virtual IAsyncDbTransaction BeginTransaction(IsolationLevel isolationLevel)

Parameters

isolationLevel IsolationLevel

Transaction isolation level.

Returns

IAsyncDbTransaction

Database transaction object.

BeginTransactionAsync(IsolationLevel, CancellationToken)

Starts new transaction asynchronously for current connection with specified isolation level.

public virtual Task<IAsyncDbTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)

Parameters

isolationLevel IsolationLevel

Transaction isolation level.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<IAsyncDbTransaction>

Database transaction object.

BeginTransactionAsync(CancellationToken)

Starts new transaction asynchronously for current connection with default isolation level.

public virtual Task<IAsyncDbTransaction> BeginTransactionAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<IAsyncDbTransaction>

Database transaction object.

Close()

Closes the connection to the database. This is the preferred method of closing any open connection.

public virtual void Close()

Exceptions

DbException

The connection-level error that occurred while opening the connection.

CloseAsync()

Closes current connection asynchonously.

public virtual Task CloseAsync()

Returns

Task

Async operation task.

CreateCommand()

Creates and returns a DbCommand object associated with the current connection.

public virtual DbCommand CreateCommand()

Returns

DbCommand

A DbCommand object.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public virtual Task DisposeAsync()

Returns

Task

Open()

Opens a database connection with the settings specified by the ConnectionString.

public virtual void Open()

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 Task OpenAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task

A task representing the asynchronous operation.

TryClone()

Returns cloned connection instance, if underlying provider supports cloning or null otherwise.

public virtual DbConnection? TryClone()

Returns

DbConnection