为什么SqlTransaction.Rollback会抛出SqlException(11,-2)(即SQL超时异常)

时间:2023-11-24 19:37:14

// System.Data.SqlClient.SqlTransaction
public override void Rollback()
{
    if (this.IsYukonPartialZombie)
    {
        if (Bid.AdvancedOn)
        {
            Bid.Trace("<sc.SqlTransaction.Rollback|ADV> %d# partial zombie no rollback required\n", this.ObjectID);
        }
        this._internalTransaction = null;
        return;
    }
    this.ZombieCheck();
    SqlStatistics statistics = null;
    IntPtr intPtr;
    Bid.ScopeEnter(out intPtr, "<sc.SqlTransaction.Rollback|API> %d#", this.ObjectID);
    SNIHandle target = null;
    RuntimeHelpers.PrepareConstrainedRegions();
    try
    {
        target = SqlInternalConnection.GetBestEffortCleanupTarget(this._connection);
        statistics = SqlStatistics.StartTimer(this.Statistics);
        this._isFromAPI = true;
        this._internalTransaction.Rollback();
    }
    catch (OutOfMemoryException e)
    {
        this._connection.Abort(e);
        throw;
    }
    catch (*Exception e2)
    {
        this._connection.Abort(e2);
        throw;
    }
    catch (ThreadAbortException e3)
    {
        this._connection.Abort(e3);
        SqlInternalConnection.BestEffortCleanup(target);
        throw;
    }
    finally
    {
        this._isFromAPI = false;
        SqlStatistics.StopTimer(statistics);
        Bid.ScopeLeave(ref intPtr);
    }
}

// System.Data.SqlClient.SqlInternalTransaction
internal void Rollback()
{
    IntPtr intPtr;
    Bid.ScopeEnter(out intPtr, "<sc.SqlInternalTransaction.Rollback|API> %d#", this.ObjectID);
    if (this._innerConnection.IsLockedForBulkCopy)
    {
        throw SQL.ConnectionLockedForBcpEvent();
    }
    this._innerConnection.ValidateConnectionForExecute(null);
    try
    {
        this._innerConnection.ExecuteTransaction(SqlInternalConnection.TransactionRequest.IfRollback, null, IsolationLevel.Unspecified, null, false);
        this.Zombie();
    }
    catch (Exception e)
    {
        if (!ADP.IsCatchableExceptionType(e))
        {
            throw;
        }
        this.CheckTransactionLevelAndZombie();
        if (!this._disposing)
        {
            throw;
        }
    }
    finally
    {
        Bid.ScopeLeave(ref intPtr);
    }
}

// System.Data.SqlClient.SqlInternalConnectionTds
internal override void ExecuteTransaction(SqlInternalConnection.TransactionRequest transactionRequest, string name, IsolationLevel iso, SqlInternalTransaction internalTransaction, bool isDelegateControlRequest)
{
    if (base.IsConnectionDoomed)
    {
        if (transactionRequest == SqlInternalConnection.TransactionRequest.Rollback || transactionRequest == SqlInternalConnection.TransactionRequest.IfRollback)
        {
            return;
        }
        throw SQL.ConnectionDoomed();
    }
    else
    {
        if ((transactionRequest == SqlInternalConnection.TransactionRequest.Commit || transactionRequest == SqlInternalConnection.TransactionRequest.Rollback || transactionRequest == SqlInternalConnection.TransactionRequest.IfRollback) && !this.Parser.MARSOn && this.Parser._physicalStateObj.BcpLock)
        {
            throw SQL.ConnectionLockedForBcpEvent();
        }
        string transactionName = (name == null) ? string.Empty : name;
        if (!this._parser.IsYukonOrNewer)
        {
            this.ExecuteTransactionPreYukon(transactionRequest, transactionName, iso, internalTransaction);
            return;
        }
        this.ExecuteTransactionYukon(transactionRequest, transactionName, iso, internalTransaction, isDelegateControlRequest);
        return;
    }
}