【问题标题】:TransactionScope Complete() doesn't commit the transaction before exiting the USING statementTransactionScope Complete() 在退出 USING 语句之前不提交事务
【发布时间】:2013-04-25 20:09:07
【问题描述】:

我遇到了这种奇怪的行为,即事务仅在 using 退出时提交,而不是在调用 scope.Complete(); 时提交

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
       {
        scope.Complete();
           // data still doesn't show in db
       }
       // now shows in db

如何在退出using 语句之前提交事务?

【问题讨论】:

标签: c# .net transactionscope


【解决方案1】:

来自documentation

如果 TransactionScope 对象创建了事务,则资源管理器之间的实际提交工作发生在 End Using 语句中。

所以看起来你不能在 using 语句结束之前真正提交事务。

【讨论】:

  • 主要原因是它可能嵌套在另一个范围内,所以你所说的只是“我在这里的工作看起来不错”但稍后失败可能仍想回滚如果它是更大行动的一部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-10
  • 2011-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多