/// <summary> /// Rollbacks the transaction. /// </summary> public SqlContextResult RollbackTransaction() { SqlContextResult isok = SqlContextResult.Ok; try { if (mTransaction != null) { mTransaction.Rollback(); } else { isok = SqlContextResult.NoTransactionToRollback; } } catch (Exception ex) { EventLogger.SendMsg(ex); isok = SqlContextResult.TransactionRollbackError; } finally { mTransaction.Dispose(); mTransaction = null; mConnection.Close(); } return(isok); }
/// <summary> /// Opens the transaction. /// </summary> /// <param name="isolationLevel">The isolation level.</param> /// <returns></returns> public SqlContextResult OpenTransaction(IsolationLevel isolationLevel = IsolationLevel.RepeatableRead) { SqlContextResult isok = SqlContextResult.Ok; if (mIsTransactional) { try { mConnection.Open(); try { mTransaction = mConnection.BeginTransaction(isolationLevel, Guid.NewGuid().ToString().XDwLeft(32).ToString()); } catch (Exception ex) { EventLogger.SendMsg(ex); isok = SqlContextResult.ErrorOpeningTransaction; } } catch (Exception ex) { EventLogger.SendMsg(ex); isok = SqlContextResult.ErrorOpeningConnection; } } else { isok = SqlContextResult.ContextNotTransactional; } return(isok); }
/// <summary> /// Commits the transaction. /// </summary> public SqlContextResult CommitTransaction() { SqlContextResult isok = SqlContextResult.Ok; try { if (mTransaction != null) { this.mTransaction.Commit(); } else { isok = SqlContextResult.NoTransactionToCommit; } } catch (Exception ex) { EventLogger.SendMsg(ex); isok = SqlContextResult.CommitTransactionError; } finally { mTransaction.Dispose(); mTransaction = null; mConnection.Close(); } return(isok); }
/// <summary> /// Closes the connection. /// </summary> /// <returns></returns> public SqlContextResult CloseConnection() { SqlContextResult isok = SqlContextResult.Ok; try { mConnection.Close(); } catch (Exception ex) { EventLogger.SendMsg(ex); isok = SqlContextResult.ConnectionCloseError; } return(isok); }
/// <summary> /// Opens the connection. /// </summary> /// <returns></returns> public SqlContextResult OpenConnection() { SqlContextResult isok = SqlContextResult.Ok; try { if (!ConnectionIsOpen) { mConnection.Open(); } else { isok = SqlContextResult.ConnectionAlreadyOpened; } } catch (Exception ex) { EventLogger.SendMsg(ex); isok = SqlContextResult.ErrorOpeningConnection; } return(isok); }