/// <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; } } }
/// <summary> /// Used when a connection is closed /// </summary> public void Prepare() { Log.Debug("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. _connection.Connector.ClearTransaction(); _npgsqlTx.Dispose(); _npgsqlTx = null; _connection.PromotableLocalTransactionEnded(); } } }
void Dispose() { if (_isDisposed) { return; } Debug.Assert(_transaction != null, "No transaction"); Debug.Assert(_connector != null, "No connector"); Log.CleaningUpResourceManager(_connector.Id, _txId); if (_localTx != null) { _localTx.Dispose(); _localTx = null; } if (_connector.Connection != null) { _connector.Connection.EnlistedTransaction = null; } else { // We're here for connections which were closed before their TransactionScope completes. // These need to be closed now. if (_connector.Settings.Pooling) { ConnectorPool pool; lock (PoolManager.Pools) { var found = PoolManager.Pools.TryGetValue(_connector.ConnectionString, out pool); Debug.Assert(found); } pool.RemovePendingEnlistedConnector(_connector, _transaction); pool.Release(_connector); } else { _connector.Close(); } } _connector = null; _transaction = null; _isDisposed = true; }
#pragma warning disable CS8625 void Dispose() { if (_isDisposed) { return; } Log.Trace($"Cleaning up resource manager (localid={_txId}", _connector.Id); if (_localTx != null) { _localTx.Dispose(); _localTx = null; } if (_connector.Connection != null) { _connector.Connection.EnlistedTransaction = null; } else { // We're here for connections which were closed before their TransactionScope completes. // These need to be closed now. if (_connector.Settings.Pooling) { var found = PoolManager.TryGetValue(_connector.ConnectionString, out var pool); Debug.Assert(found); pool !.TryRemovePendingEnlistedConnector(_connector, _transaction); pool.Return(_connector); } else { _connector.Close(); } } _connector = null !; _transaction = null !; _isDisposed = true; }
public void Enlist(Transaction tx) { _log.Debug("Enlist"); if (tx != null) { _isolationLevel = tx.IsolationLevel; if (!tx.EnlistPromotableSinglePhase(this)) { // must already have a durable resource // start transaction _npgsqlTx = _connection.BeginTransaction(ConvertIsolationLevel(_isolationLevel)); _inTransaction = true; _rm = CreateResourceManager(); _callbacks = new NpgsqlTransactionCallbacks(_connection); _rm.Enlist(_callbacks, TransactionInterop.GetTransmitterPropagationToken(tx)); // enlisted in distributed transaction // disconnect and cleanup local transaction _connection.Connector.ClearTransaction(); _npgsqlTx.Dispose(); _npgsqlTx = null; } } }
public void Enlist(Transaction tx) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Enlist"); if (tx != null) { _isolationLevel = tx.IsolationLevel; if (!tx.EnlistPromotableSinglePhase(this)) { // must already have a durable resource // start transaction _npgsqlTx = _connection.BeginTransaction(ConvertIsolationLevel(_isolationLevel)); _inTransaction = true; _rm = CreateResourceManager(); _callbacks = new NpgsqlTransactionCallbacks(_connection); _rm.Enlist(_callbacks, TransactionInterop.GetTransmitterPropagationToken(tx)); // enlisted in distributed transaction // disconnect and cleanup local transaction _npgsqlTx.Cancel(); _npgsqlTx.Dispose(); _npgsqlTx = null; } } }
public static void ReleaseTransaction(ref NpgsqlTransaction pPgsTrans) { try { pPgsTrans.Commit(); pPgsTrans.Dispose(); pPgsTrans = null; GC.Collect(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "ReleaseTransaction"); } }