public void CreateTransaction() { try { Trans = Conn.BeginTransaction(); } catch (Exception) { throw; } }
/// <summary> /// Crea un objeto Transaccion de la base de datos y la retorna como 'object' /// </summary> /// <param name="unaConexion">Una conexion con estado Open</param> /// <returns>Transaccion como 'object'</returns> public override object CreaTransaccion(object unaConexion) { IfxConnection conn = ((IfxConnection)unaConexion); IfxTransaction transaccion = conn.BeginTransaction(); return(transaccion); }
public void BeginTransaction() { connection = new IfxConnection(chain); connection.Open(); transaction = connection.BeginTransaction(); handding_transaction = true; }
/// <summary> /// Perform a simaple commit, rollback transaction operation /// </summary> private bool PerformTransaction() { bool bStatus = false; IfxTransaction tx; try { // ********************* Demo for Transaction Commit ******************** tx = _connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); _command = _connection.CreateCommand(); _command.Transaction = tx; _command.CommandText = "insert into transactiontable values(1, 'ORIGINAL NAME');"; WriteLine("Inserting into table with the command: " + _command.CommandText); _command.ExecuteNonQuery(); _command.CommandText = "update transactiontable set name='NAME UPDATED' where id='1';"; WriteLine("Update table with the command: " + _command.CommandText); _command.ExecuteNonQuery(); tx.Commit(); WriteLine("Transaction Commited. Observe table contents"); _command.CommandText = "select * from transactiontable"; WriteLine("Results after executing the command: " + _command.CommandText); _dataReader = _command.ExecuteReader(); while (_dataReader.Read()) { WriteLine(String.Format("{0} ----- {1}", _dataReader[0], _dataReader[1])); } _dataReader.Close(); // ********************* Demo for Transaction Rollback ******************** tx = _connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); _command = _connection.CreateCommand(); _command.Transaction = tx; _command.CommandText = "update transactiontable set name='NAME ROLLEDBACK' where id='1';"; WriteLine("Update table with the command: " + _command.CommandText); _command.ExecuteNonQuery(); WriteLine("Observe table contents before rollback"); _command.CommandText = "select * from transactiontable"; WriteLine("Results after executing the command: " + _command.CommandText); _dataReader = _command.ExecuteReader(); while (_dataReader.Read()) { WriteLine(String.Format("{0} ----- {1}", _dataReader[0], _dataReader[1])); } _dataReader.Close(); tx.Rollback(); WriteLine("Observe table contents after rollback"); _command.CommandText = "select * from transactiontable"; WriteLine("Results after executing the command: " + _command.CommandText); _dataReader = _command.ExecuteReader(); while (_dataReader.Read()) { WriteLine(String.Format("{0} ----- {1}", _dataReader[0], _dataReader[1])); } _dataReader.Close(); bStatus = true; } catch (Exception excep) { WriteLine(String.Format("Insert into table failed : {0}", excep.Message)); bStatus = false; } return(bStatus); }