3

我查看了 System.Data.SqlClient.SqlTransaction 中的 Dispose() 方法(使用反编译器):

 protected override void Dispose(bool disposing)
    {
      if (disposing)
      {
        SNIHandle target = (SNIHandle) null;
        RuntimeHelpers.PrepareConstrainedRegions();
        try
        {
          target = SqlInternalConnection.GetBestEffortCleanupTarget(this._connection);
          if (!this.IsZombied)
          {
            if (!this.IsYukonPartialZombie)
              this._internalTransaction.Dispose();
          }
        }
        catch (OutOfMemoryException ex)
        {
          this._connection.Abort((Exception) ex);
          throw;
        }
        catch (StackOverflowException ex)
        {
          this._connection.Abort((Exception) ex);
          throw;
        }
        catch (ThreadAbortException ex)
        {
          this._connection.Abort((Exception) ex);
          SqlInternalConnection.BestEffortCleanup(target);
          throw;
        }
      }
      base.Dispose(disposing);
    }

为什么大家在论坛里都说dispose是Rolling back?它在哪里回滚?

4

1 回答 1

4

@BlorgBeard 说“我相信内部事务在其自己的 Dispose 中回滚 - 即在 this._internalTransaction.Dispose(); 中”是正确的。写它作为其他人的答案。(见最后声明)

System.Data.SqlClient.SqlInternalTransaction.Dispose() 的代码——见最后一行:

private void Dispose(bool disposing)
{
  Bid.PoolerTrace("<sc.SqlInteralTransaction.Dispose|RES|CPOOL> %d#, Disposing\n", this.ObjectID);
  if (!disposing || this._innerConnection == null)
    return;
  this._disposing = true;
  this.Rollback();
}
于 2012-06-25T22:10:15.853 回答