Npgsql.NpgsqlTransaction.Rollback C# (CSharp) Method

Rollback() public method

Rolls back a transaction from a pending savepoint state.
public Rollback ( String savePointName ) : void
savePointName String
return void
        public void Rollback(String savePointName)
        {

            CheckDisposed();

            if (_conn == null)
            {
                throw new InvalidOperationException(resman.GetString("Exception_NoTransaction"));
            }

            if (!_conn.Connector.SupportsSavepoint)
            {
                throw new InvalidOperationException(resman.GetString("Exception_SavePointNotSupported"));
            }

            if (savePointName.Contains(";"))
            {
                throw new InvalidOperationException(resman.GetString("Exception_SavePointWithSemicolon"));

            }

            NpgsqlCommand.ExecuteBlind(_conn.Connector, string.Format("ROLLBACK TO SAVEPOINT {0}", savePointName));
        }

Same methods

NpgsqlTransaction::Rollback ( ) : void

Usage Example

示例#1
0
        /// <summary>
        /// Repeatedly attempts to rollback, to support timeout-triggered rollbacks that occur while the connection is busy.
        /// </summary>
        void RollbackLocal()
        {
            Debug.Assert(_connector != null, "No connector");
            Debug.Assert(_localTx != null, "No local transaction");

            var attempt = 0;

            while (true)
            {
                try
                {
                    _localTx.Rollback();
                    return;
                }
                catch (NpgsqlOperationInProgressException)
                {
                    // This really shouldn't be necessary, but just in case
                    if (attempt++ == MaximumRollbackAttempts)
                    {
                        throw new Exception($"Could not roll back after {MaximumRollbackAttempts} attempts, aborting. Transaction is in an unknown state.");
                    }

                    Log.Logger.LogWarning(NpgsqlEventId.ConnectionInUseDuringRollback, "[{ConnectorId}] Connection in use while trying to rollback, will cancel and retry (localid={TransactionId}", _connector.Id, _txId);
                    _connector.CancelRequest();
                    // Cancellations are asynchronous, give it some time
                    Thread.Sleep(500);
                }
            }
        }
All Usage Examples Of Npgsql.NpgsqlTransaction::Rollback