Transactionscope异常处理 [英] Transactionscope Exception Handling

查看:201
本文介绍了Transactionscope异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为TransactionAbortedException的文档缺少什么时候可以发生.

如果您不对初始交易执行Scope.Complete,则不会发生这种情况.换句话说,无法执行Scope.Complete意味着它将使用block静默退出transactionscope. (由于没有其他方法可以静默取消transactionscope,因此可以接受,但应清楚记录在案.)
如果您需要警告您的流程您正在中止初始事务,则应通过抛出异常来这样做,该异常将自动以静默方式关闭transactionscope.您可能希望使用block来尝试/捕获包装您的transactionscope,以捕获这些异常.

但是,如果使用连接到环境事务的块对具有自己的transactionscope的进程进行了多个相同级别的调用,则在调用Scope.Complete失败时将获得异常.当后续调用启动transactionscope时,它会看到一个肮脏的事务,并会在该点发出transactionabortedexception.
但是,如果您嵌套调用,并且子调用未发出scope.complete,则在它上面打开的任何其他子调用在发出scope.complete()时都不会发出中止异常,只有在另一个调用时才会被捕获.尝试进行事务处理,或者当初始transasctionscope发出scope.complete时.

I think the documentation on TransactionAbortedException is a little lacking as to when it can happen.

It DOES NOT happen if you do not do a Scope.Complete on your initial transaction. In other words, failure to execute Scope.Complete means that it will silently exit a transactionscope using block. (Since there is no other way to cancel the transactionscope silently, this is acceptable but should be documented clearly.)
If you need to alert your processes that you are aborting the initial transaction, you should do so by throwing an exception, which will silently close the transactionscope automatically. You may want to have a try/catch wrapping your transactionscope using block to catch these exceptions.

However, if have multiple same level calls to processes that have their own transactionscope using block that join the ambient transaction, you will get the exception if you fail to Scope.Complete on a call. When a subsequent call initiates the transactionscope, it sees a dirty transaction and will issue the transactionabortedexception at that point.
However, if you are nesting calls and the child call does not issue a scope.complete, then any other child call open above it will NOT issue an abort exception when it issues a scope.complete(), it will only be caught if another transaction is attempted or when the initial transasctionscope issues a scope.complete.

推荐答案

据我了解,这不是问题.

您在这里看到的内容很重要,因此,我建议您写一篇简短的提示/技巧"文章,并通过以下页面发布: http ://www.codeproject.com/Tips/post.aspx [ ^ ].

谢谢
—SA
As I understand, this is not a question.

What you right here looks important, so I would advice you write a short Tips/Trick article and post it by using this page: http://www.codeproject.com/Tips/post.aspx[^].

Thank you,
—SA


提示和问题是否都在同一时间搜索?如果不是这样,那么在我看来,任何寻求transactionscope异常问题的人都希望在问题中找到它.
布莱恩
Are tips and questions both searched at the same time? If not, then anyone looking for transactionscope exception issues would want to find this in questions in my opinion.
Brian


这篇关于Transactionscope异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆