Exemplo n.º 1
0
 public void AbortTransaction()
 {
     useTransaction = false;
     _transaction.Rollback();
     _transaction.Dispose();
     _transaction = null;
 }
Exemplo n.º 2
0
 public void EndTransaction(bool blnCommit)
 {
     try
     {
         if (blnCommit == true)
         {
             objTransaction.Commit();
         }
         else
         {
             objTransaction.Rollback();
         }
     }
     catch (Exception ex)
     {
         objException = ex;
     }
     finally
     {
         //objClear.CleanupPooledConnections();
         objConnection.Close();
         objTransaction.Dispose();
         objTransaction = null;
         blnTrans       = false;
         if (objCommand is object)
         {
             objCommand.Dispose();
             objCommand = null;
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Use this for Insert, Update and Delete
        /// Functionality to provide the gateway to access the Data Access Layer with Transaction object
        /// If any exception transaction will be rollbacked here
        /// </summary>
        /// <param name="destinationDatabase"></param>
        /// <param name="givenTransaction">The given transaction.</param>
        /// <returns></returns>
        public ErrorObj DB2Access(DestinationDatabase destinationDatabase, iDB2Transaction givenTransaction)
        {
            string   ModuleName = GetModuleNameByDestinationDB(destinationDatabase);
            ErrorObj err        = new ErrorObj();

            this.GetConnectionDetails(Settings.BusinessUnit, "", ModuleName);
            Settings.ModuleName = ModuleName;
            DBDB2Access DBDataAccessEntity = new DBDB2Access();

            DBDataAccessEntity.Settings       = Settings;
            DBDataAccessEntity.CommandElement = _commandElements;
            err = DBDataAccessEntity.AccessWithTransaction(givenTransaction);
            if (!err.HasError && !(DBDataAccessEntity.ResultDataSet == null))
            {
                ResultDataSet = DBDataAccessEntity.ResultDataSet;
            }
            else
            {
                givenTransaction.Rollback();
                //before call this get the previous error details
                string errMessage = err.ErrorMessage;
                err = EndTransaction(destinationDatabase, givenTransaction);
                if (err.HasError)
                {
                    errMessage = errMessage + ";" + err.ErrorMessage;
                }
                //whether end transaction gives error or not
                //always assign err object has error
                err.HasError     = true;
                err.ErrorMessage = errMessage;
            }
            return(err);
        }
Exemplo n.º 4
0
 public void CancelarTransaccion()
 {
     if (_Transaccion != null)
     {
         _Transaccion.Rollback();
         EliminaTransaccion();
     }
 }
Exemplo n.º 5
0
 public void Rollback()
 {
     transaction.Rollback();
     connection.Dispose();
     connection.Close();
     transaction = null;
     connection  = null;
 }
Exemplo n.º 6
0
        public static long GetSequenceTrans(iDB2Connection conn, string tableName)
        {
            //iDB2Transaction trans = conn.BeginTransaction(IsolationLevel.RepeatableRead);
            iDB2Transaction trans = conn.BeginTransaction();
            long            id    = 0;

            try {
                string          sql   = "SELECT VALUE FROM SEQ_TABLE WHERE KEY=@KEY";
                iDB2Parameter[] parms = new iDB2Parameter[] {
                    new iDB2Parameter("@KEY", "USER")
                };
                Object obj = ExecuteScalar(trans, CommandType.Text, sql, parms);
                if (obj != null)
                {
                    id = Convert.ToInt32(obj);
                    string          sqlUpdate   = "UPDATE SEQ_TABLE SET VALUE=@NEW_ID WHERE VALUE=@OLD_ID AND KEY=@KEY";
                    iDB2Parameter[] parmsUpdate = new iDB2Parameter[] {
                        new iDB2Parameter("@NEW_ID", id + 1),
                        new iDB2Parameter("@OLD_ID", id),
                        new iDB2Parameter("@KEY", tableName)
                    };
                    ExecuteNonQuery(trans, CommandType.Text, sqlUpdate, parmsUpdate);
                }
                else
                {
                    id = 1;
                    string          sqlInsert   = "INSERT INTO SEQ_TABLE(KEY,VALUE) VALUES(@KEY,@VALUE)";
                    iDB2Parameter[] parmsInsert = new iDB2Parameter[] {
                        new iDB2Parameter("@KEY", tableName),
                        new iDB2Parameter("@VALUE", id + 1)
                    };
                    ExecuteNonQuery(trans, CommandType.Text, sqlInsert, parmsInsert);
                }
                trans.Commit();
                return(id);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                log.Error(ex.StackTrace);
                trans.Rollback();
                return(0);
            }
        }