• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
PowerCoder
博客园    首页    新随笔    联系   管理    订阅  订阅

关于TransactionScope.Complete方法(链接)

相信有些同学会困扰,当我们执行TransactionScope.Complete()方法的时候,是否Transaction被真正提交到数据库了。

对于这一点,MSDN上有这么一段描述:

If the TransactionScope object created the transaction initially, the actual work of committing the transaction by the transaction manager occurs after the last line of code in the using block. If it did not create the transaction, the commit occurs whenever Commit is called by the owner of the CommittableTransaction object. At that point the transaction manager calls the resource managers and informs them to either commit or rollback, based on whether the Complete method was called on the TransactionScope object.

请查看:Implementing an Implicit Transaction using Transaction Scope 特别是这个部分。同样TransactionScope.Complete的介绍文档也有说到这一点。

 

同样在TransactionScope.Dispose的介绍文档,也有说到:

Calling this method marks the end of the transaction scope. If the TransactionScope object created the transaction and Complete was called on the scope, the TransactionScope object attempts to commit the transaction when this method is called. 

 

所以,实际上TransactionScope提交Transaction到数据库的时间点是在using语句块的最后,也就是在调用TransactionScope.Dispose()方法的时候。

 

posted @ 2020-02-06 11:28  PowerCoder  阅读(631)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3