Table of Contents

Class GeneralConnection

Namespace
CMS.DataEngine
Assembly
CMS.DataEngine.dll

Represents a general database connection.

public class GeneralConnection : IDataConnection
Inheritance
object
GeneralConnection
Implements
Extension Methods

Constructors

GeneralConnection(string)

Constructor.

protected GeneralConnection(string connectionString)

Parameters

connectionString string

Connection string. If no connection string is provided, CMSConnectionString configuration value is used instead

Properties

CommandTimeout

Command timeout.

public int CommandTimeout { get; set; }

Property Value

int

ConnectionString

Connection string for specific provider.

public string ConnectionString { get; }

Property Value

string

DataConnection

Data connection for specific provider.

public IDataConnection DataConnection { get; set; }

Property Value

IDataConnection

KeepOpen

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

public bool KeepOpen { get; set; }

Property Value

bool

UseScopeConnection

If true, the connection uses the scope connection

public bool UseScopeConnection { get; set; }

Property Value

bool

Methods

BulkInsert(DataTable, string, BulkInsertSettings)

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

public virtual 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 insertion settings

Close()

Closes the connection.

public void Close()

Dispose()

Disposes the connection

public void Dispose()

ExecuteNonQuery(QueryParameters)

Executes the query and returns the number of rows affected.

public virtual int ExecuteNonQuery(QueryParameters query)

Parameters

query QueryParameters

Query parameters.

Returns

int

ExecuteNonQueryAsync(QueryParameters, CancellationToken)

An asynchronous version of ExecuteNonQuery(QueryParameters) 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.

public virtual Task<int> ExecuteNonQueryAsync(QueryParameters query, CancellationToken cancellationToken)

Parameters

query QueryParameters

Query parameters.

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<int>

A task representing the asynchronous operation.

ExecuteQuery(QueryParameters)

Executes query and returns result as a System.Data.DataSet.

public virtual DataSet ExecuteQuery(QueryParameters query)

Parameters

query QueryParameters

Query parameters

Returns

DataSet

Remarks

The method performs a retry of the query execution if an SQL deadlock occurs and the query is not part of a transaction. The retry is performed at most 3 times.

ExecuteQuery(QueryParameters, ref int)

Executes query and returns result as a DataSet. Returns the total number of result items.

public virtual DataSet ExecuteQuery(QueryParameters query, ref int totalRecords)

Parameters

query QueryParameters

Query parameters

totalRecords int

Returns total records

Returns

DataSet

ExecuteReader(QueryParameters, CommandBehavior)

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

public virtual DbDataReader ExecuteReader(QueryParameters query, CommandBehavior commandBehavior)

Parameters

query QueryParameters

Query parameters.

commandBehavior CommandBehavior

Command behavior.

Returns

DbDataReader

Remarks

The method performs a retry of the query execution if an SQL deadlock occurs and the query is not part of a transaction. The retry is performed at most 3 times.

ExecuteReaderAsync(QueryParameters, CommandBehavior, CancellationToken)

An asynchronous version of ExecuteReader(QueryParameters, 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.

public virtual Task<DbDataReader> ExecuteReaderAsync(QueryParameters query, CommandBehavior commandBehavior, CancellationToken cancellationToken)

Parameters

query QueryParameters

Query parameters.

commandBehavior CommandBehavior

Command behavior.

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<DbDataReader>

A task representing the asynchronous operation.

ExecuteReaderCore(QueryParameters, CommandBehavior)

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

protected virtual DbDataReader ExecuteReaderCore(QueryParameters query, CommandBehavior commandBehavior)

Parameters

query QueryParameters

Query parameters.

commandBehavior CommandBehavior

Command behavior.

Returns

DbDataReader

Remarks

The method is called by ExecuteReader(QueryParameters, CommandBehavior) as part of each try, if the query execution is being retried.

ExecuteScalar(QueryParameters)

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.

public virtual object ExecuteScalar(QueryParameters query)

Parameters

query QueryParameters

Query parameters.

Returns

object

ExecuteScalarAsync(QueryParameters, CancellationToken)

An asynchronous version of ExecuteScalar(QueryParameters), 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.

public virtual Task<object> ExecuteScalarAsync(QueryParameters queryParameters, CancellationToken cancellationToken)

Parameters

queryParameters QueryParameters

Query parameters.

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

public 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 the connection is open.

public bool IsOpen()

Returns

bool

Open()

Opens the connection.

public void Open()

RunQuery(QueryParameters)

Runs the query against SQL DB.

protected virtual DataSet RunQuery(QueryParameters query)

Parameters

query QueryParameters

Query to run

Returns

DataSet