c# – 如果在Using块的末尾未调用TransactionScope.Complete,则Transaction会发生什么
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 如果在Using块的末尾未调用TransactionScope.Complete,则Transaction会发生什么,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1131字,纯文字阅读大概需要2分钟。
内容图文
![c# – 如果在Using块的末尾未调用TransactionScope.Complete,则Transaction会发生什么](/upload/InfoBanner/zyjiaocheng/812/5be072b49fe34731b4e504fc51dd08f4.jpg)
我使用的是SQL Server 2012,并且在TransactionScope Using块中有多个SQL连接到同一个数据库.但是,如果第一次更新SQL操作没有产生所需的输出,那么我将跳过对SQL操作的下一次调用,并且还调用在使用块结束时未调用的TransactionScope.Complete.
解决方法:
您需要的大部分信息都在这里很好地列出了Completing a transaction scope
When your application completes all the work it wants to perform in a
transaction, you should call the Complete method only once to inform
the transaction manager that it is acceptable to commit the
transaction. It is very good practice to put the call to Complete as
the last statement in the using block.Failing to call this method aborts the transaction, because the
transaction manager interprets this as a system failure, or equivalent
to an exception thrown within the scope of the transaction. However,
calling this method does not guarantee that the transaction wil be
committed. It is merely a way of informing the transaction manager of
your status. After calling the Complete method, you can no longer
access the ambient transaction by using the Current property, and
attempting to do so will result in an exception being thrown.
内容总结
以上是互联网集市为您收集整理的c# – 如果在Using块的末尾未调用TransactionScope.Complete,则Transaction会发生什么全部内容,希望文章能够帮你解决c# – 如果在Using块的末尾未调用TransactionScope.Complete,则Transaction会发生什么所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。