我查看了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);
}
为什么每个人都在论坛中说它正在回滚处置?它在哪里回滚?
答案 0 :(得分: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();
}