private void CommitInternal() { if (null == _transaction) { return; } if (null != _nestedTransaction) { OleDbTransaction transaction = (OleDbTransaction)_nestedTransaction.Target; if ((null != transaction) && _nestedTransaction.IsAlive) { transaction.CommitInternal(); } _nestedTransaction = null; } OleDbHResult hr = _transaction.Commit(); if (!_transaction.MustComplete) { _transaction.Dispose(); _transaction = null; DisposeManaged(); } if (hr < 0) { // if an exception is thrown, user can try to commit their transaction again ProcessResults(hr); } }
/// commit the transaction public void Commit() { string TransactionIdentifier = null; bool TransactionValid = false; IsolationLevel TransactionIsolationLevel = IsolationLevel.Unspecified; // Attempt to commit the DB Transaction. try { // 'Sanity Check': Check that TheTransaction hasn't been committed or rolled back yet. if (!Valid) { var Exc1 = new EDBAttemptingToUseTransactionThatIsInvalidException( "TDataBase.CommitTransaction called on DB Transaction that isn't valid", ThreadingHelper.GetThreadIdentifier(ThreadThatTransactionWasStartedOn), ThreadingHelper.GetCurrentThreadIdentifier()); TLogging.Log(Exc1.ToString()); throw Exc1; } if (TLogging.DL >= DBAccess.DB_DEBUGLEVEL_TRANSACTION_DETAIL) { // Gather information for logging TransactionIdentifier = GetDBTransactionIdentifier(); TransactionValid = Valid; TransactionIsolationLevel = IsolationLevel; } WrappedTransaction.Commit(); TLogging.LogAtLevel(DBAccess.DB_DEBUGLEVEL_TRANSACTION, " Transaction " + FTransactionName + " in Connection " + FTDataBaseInstanceThatTransactionBelongsTo.ConnectionName + " committed"); // Commit was OK, now clean up. Dispose(); TLogging.LogAtLevel(DBAccess.DB_DEBUGLEVEL_TRANSACTION_DETAIL, String.Format( "DB Transaction{0} got rolled back. Before that, its DB Transaction Properties were: Valid: {1}, " + "IsolationLevel: {2} (it got started on Thread {3} in AppDomain '{4}').", TransactionIdentifier, TransactionValid, TransactionIsolationLevel, ThreadThatTransactionWasStartedOn, AppDomainNameThatTransactionWasStartedIn) ); } catch (Exception Exc) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. // // MSDN says: "Try/Catch exception handling should always be used when rolling back a // transaction. A Rollback generates an InvalidOperationException if the connection is // terminated or if the transaction has already been rolled back on the server." TLogging.Log("Exception while attempting Transaction rollback: " + Exc.ToString()); } }