Table of Contents

Interface IDataConnection

Namespace
CMS.DataEngine
Assembly
CMS.DataEngine.dll

Data connection interface that must be implemented by data providers.

public interface IDataConnection
Extension Methods

Properties

CommandTimeout

Command timeout which will be set on this connection.

int CommandTimeout { get; set; }

Property Value

int

Remarks

If a new CMSConnectionScope is created within this connection and a different CommandTimeout is set, the current connection timeout is not changed outside of the scope.

ConnectionString

Connection string for specific provider.

string ConnectionString { get; }

Property Value

string

KeepOpen

If true, the connection stays open even if close is requested.

bool KeepOpen { get; set; }

Property Value

bool

NativeConnection

Native connection object. It depends on provider type.

IDbConnection NativeConnection { get; set; }

Property Value

IDbConnection

Transaction

Transaction object.

IDbTransaction Transaction { get; set; }

Property Value

IDbTransaction

UseScopeConnection

If true, the connection uses the scope connection

bool UseScopeConnection { get; set; }

Property Value

bool

Methods

BeginTransaction()

Begins a new transaction.

void BeginTransaction()

BeginTransaction(IsolationLevel)

Begins a new transaction with specified isolation level.

void BeginTransaction(IsolationLevel isolationLevel)

Parameters

isolationLevel IsolationLevel

Isolation level to use

BulkInsert(DataTable, string, BulkInsertSettings)

Performs a bulk insert of the data into a target database table

void BulkInsert(DataTable sourceData, string targetTable, BulkInsertSettings insertSettings = null)

Parameters

sourceData DataTable

Source data table

targetTable string

Name of the target DB table

insertSettings BulkInsertSettings

Bulk insert configuration

Close()

Closes connection to the database.

void Close()

CommitTransaction()

Commits current transaction.

void CommitTransaction()

ExecuteNonQuery(string, QueryDataParameters, QueryTypeEnum, bool)

Executes the query and returns the number of rows affected.

int ExecuteNonQuery(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, bool requiresTransaction)

Parameters

queryText string

Query or stored procedure to be run.

queryParams QueryDataParameters

Query parameters.

queryType QueryTypeEnum

Indicates if query is a SQL query or stored procedure.

requiresTransaction bool

If true, the query should run within transaction.

Returns

int

ExecuteNonQueryAsync(string, QueryDataParameters, QueryTypeEnum, bool, CancellationToken)

An asynchronous version of ExecuteNonQuery(string, QueryDataParameters, QueryTypeEnum, bool) which executes the query asynchronously and returns the number of rows affected.

The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.

Task<int> ExecuteNonQueryAsync(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, bool requiresTransaction, CancellationToken cancellationToken)

Parameters

queryText string

Query or stored procedure to be run.

queryParams QueryDataParameters

Query parameters.

queryType QueryTypeEnum

Indicates if query is a SQL query or stored procedure.

requiresTransaction bool

If true, the query should run within transaction.

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<int>

A task representing the asynchronous operation.

ExecuteQuery(string, QueryDataParameters, QueryTypeEnum, bool)

Returns result of the query.

DataSet ExecuteQuery(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, bool requiresTransaction)

Parameters

queryText string

Query or stored procedure to be run

queryParams QueryDataParameters

Array of query parameters

queryType QueryTypeEnum

Indicates it query is a SQL query or stored procedure

requiresTransaction bool

If true, the query should run within transaction

Returns

DataSet

ExecuteReader(string, QueryDataParameters, QueryTypeEnum, CommandBehavior)

Executes the query and returns result as a System.Data.Common.DbDataReader.

DbDataReader ExecuteReader(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, CommandBehavior commandBehavior)

Parameters

queryText string

Query or stored procedure to be run.

queryParams QueryDataParameters

Query parameters.

queryType QueryTypeEnum

Indicates if query is a SQL query or stored procedure.

commandBehavior CommandBehavior

Command behavior.

Returns

DbDataReader

ExecuteReaderAsync(string, QueryDataParameters, QueryTypeEnum, CommandBehavior, CancellationToken)

An asynchronous version of ExecuteReader(string, QueryDataParameters, QueryTypeEnum, CommandBehavior) which executes the query asynchronously and returns result as a System.Data.Common.DbDataReader.

The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.

Task<DbDataReader> ExecuteReaderAsync(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, CommandBehavior commandBehavior, CancellationToken cancellationToken)

Parameters

queryText string

Query or stored procedure to be run

queryParams QueryDataParameters

Query parameters

queryType QueryTypeEnum

Indicates it query is a SQL query or stored procedure

commandBehavior CommandBehavior

Command behavior

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<DbDataReader>

A task representing the asynchronous operation.

ExecuteScalar(string, QueryDataParameters, QueryTypeEnum, bool)

Executes the query and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

object ExecuteScalar(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, bool requiresTransaction)

Parameters

queryText string

Query or stored procedure to be run.

queryParams QueryDataParameters

Query parameters.

queryType QueryTypeEnum

Indicates if query is a SQL query or a stored procedure.

requiresTransaction bool

If true, the query should run within transaction.

Returns

object

ExecuteScalarAsync(string, QueryDataParameters, QueryTypeEnum, bool, CancellationToken)

An asynchronous version of ExecuteScalar(string, QueryDataParameters, QueryTypeEnum, bool), which executes the query asynchronously and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.

Task<object> ExecuteScalarAsync(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, bool requiresTransaction, CancellationToken cancellationToken)

Parameters

queryText string

Query or stored procedure to be run.

queryParams QueryDataParameters

Query parameters.

queryType QueryTypeEnum

Indicates if query is a SQL query or stored procedure

requiresTransaction bool

If true, the query should run within transaction.

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<object>

A task representing the asynchronous operation.

GetExecutingConnection(string, bool)

Gets the connection that executes the given query

IDataConnection GetExecutingConnection(string connectionStringName, bool newConnection = false)

Parameters

connectionStringName string

Connection string name

newConnection bool

If true, a new connection instance is created

Returns

IDataConnection

IsOpen()

Returns true if connection to the database is open.

bool IsOpen()

Returns

bool

IsTransaction()

Indicates if transaction is running.

bool IsTransaction()

Returns

bool

NativeConnectionExists()

Returns true if the native connection exists.

bool NativeConnectionExists()

Returns

bool

NativeDBConnectionExists()

Returns true if the native connection exists.

bool NativeDBConnectionExists()

Returns

bool

Open()

Opens connection to the database.

void Open()

RollbackTransaction()

Rollbacks current transaction.

void RollbackTransaction()