Npgsql.NpgsqlTransaction.Dispose C# (CSharp) Method

Dispose() protected method

Dispose.
protected Dispose ( bool disposing ) : void
disposing bool
return void
        protected override void Dispose(bool disposing)
        {
            if (disposing && this._conn != null)
            {
                if (_conn.Connector.Transaction != null)
                {
                    if ((Thread.CurrentThread.ThreadState & (ThreadState.Aborted | ThreadState.AbortRequested)) != 0)
                    {
                        // can't count on Rollback working if the thread has been aborted
                        // need to copy since Cancel will set it to null
                        NpgsqlConnection conn = _conn;
                        Cancel();
                        // must close connection since transaction hasn't been rolled back
                        conn.Close();
                    }
                    else
                    {
                        this.Rollback();
                    }
                }

                this._disposed = true;
            }
            base.Dispose(disposing);
        }

Usage Example

示例#1
0
 /// <summary>
 /// Used when a connection is closed
 /// </summary>
 public void Prepare()
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Prepare");
     if (_inTransaction)
     {
         // may not be null if Promote or Enlist is called first
         if (_callbacks == null)
         {
             _callbacks = new NpgsqlTransactionCallbacks(_connection);
         }
         _callbacks.PrepareTransaction();
         if (_npgsqlTx != null)
         {
             // cancel the NpgsqlTransaction since this will
             // be handled by a two phase commit.
             _npgsqlTx.Cancel();
             _npgsqlTx.Dispose();
             _npgsqlTx = null;
         }
     }
 }
All Usage Examples Of Npgsql.NpgsqlTransaction::Dispose