/// <summary> /// Crerate a new object of connection if not already created. /// opens a new connection if not already opened. /// </summary> private void OpenConnection() { if (WrapperSqlConnection == null) { objSqlConnection = new SqlConnection(ConnectionString); } if (WrapperSqlConnection.State == ConnectionState.Closed) { WrapperSqlConnection.Open(); } }
/// <summary> /// Begins a transaction if not already began, and adds to the transaction cache. /// </summary> /// <param name="transactionName"></param> /// <returns>Transaction object form cache.</returns> private SqlTransaction GetTransactionObject(string transactionName) { //If no transaction name is specified a default transaction is started/extracted if (transactionName == null || transactionName.Length == 0) { transactionName = DEFAULT_TRANSACTION_NAME; } if (!transactionCache.ContainsKey(transactionName)) { transactionCache.Add(transactionName, WrapperSqlConnection.BeginTransaction()); } return((SqlTransaction)transactionCache[transactionName]); }
/// <summary> /// Closes and nullifies a connection. /// </summary> /// <param name="disposeAfterClosing"></param> private void CloseSqlConnection(EDispose disposeAfterClosing) { if (WrapperSqlConnection != null) { RollbackTransaction(CloseConnection.NO); if (WrapperSqlConnection.State != ConnectionState.Closed) { WrapperSqlConnection.Close(); } if (disposeAfterClosing == EDispose.YES) { WrapperSqlConnection.Dispose(); } WrapperSqlConnection = null; } }