【发布时间】:2010-06-21 14:36:40
【问题描述】:
这个问题和我的问题有关:SQL Server and TransactionScope (with MSDTC): Sporadically can't get connection
我正在使用 .net TransactionScope 类进行一些事务编程。如果我理解正确的话,我可以通过将 SQL 调用包装在 using ts as new TransactionScope() 块中,或者使用 new TransactionScope() 然后在最后使用 TransactionScope.Dispose() 来在事务中执行一些 SQL 操作。
要提交事务,MSDN 说使用TransactionScope.Commit()。假设我想在某些情况下回滚事务,不先调用 Commit 方法,直接调用TransactionScope.Dispose() 是否足够?这是好的做法,还是应该以其他方式完成?
【问题讨论】:
-
如果你“想在某些情况下回滚事务”,你当然不想“先调用 Commit 方法”。你会想调用 Rollback 方法...
标签: .net sql transactions transactionscope