2012-06-25 91 views
3

我看着在System.Data.SqlClient.SqlTransaction的Dispose()方法(使用反编译):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); 
    } 

为什么大家都在它回滚在处置论坛上说什么?它在哪里回滚?

+2

我相信内部'Transaction'回滚在它自己的'处置' - 即在'this._internalTransaction.Dispose();' – Blorgbeard

+0

你知道如果你杀了进程,服务器自行回滚,对吧? – Joshua

回答

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(); 
}