TransactionScope的层次结构 [英] Hierarchy of TransactionScope

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

问题描述

时有可能有交易范围的层次?

Is it possible to have a hierarchy of transaction scopes?

如果外部事务的范围做了部署,将发生在内部事务范围内所做的更改是什么?

If the outer transaction scope does a dispose, what will happen to changes made in the inner transaction scope?

我的具体问题是,我有一个运行,有一个事务范围代码测试代码。当我打电话第二组代码与交易的范围,我得到无法访问已释放的对象。交易。会不会是内部事务范围的处置也处理外部事务的范围。

My particular problem is that I have test code that runs code that has a transaction scope. When I call a second set of code with a transaction scope I get "Cannot access a disposed object. Transaction". Could it be that the dispose of the inner transaction scope is also disposing the outer transaction scope.

推荐答案

我怀疑这是什么发生。作为底层技术支持分布式事务,如果有必要TransactionScopes可以嵌套一样长。例如,如果你启动一个事务,并更新数据库中的一些数据,然后调用一个函数,该函数内部,创建一个新的TransactionScope并插入一些数据到数据库B,然后是内部事务使用的环境交易,这是已经打开。然而,对于这个工作,你需要分布式事务处理协调器运行(SQL服务器)。此外,SQL Server 2005和上方有启动事务作为一个经常性交易,是否需要,而SQL 2000将启动所有这些分布式事务,因为它不具备的能力,将其提升到一个分布式事务的能力推广。

I doubt this is what is happening. TransactionScopes can be nested as long as the underlying technology supports distributed transactions, if necessary. For instance, if you start a transaction and update some data in database A, and then you call a function, and inside that function, you create a new TransactionScope and insert some data into database B, then the inner transaction uses the "ambient" transaction that was already open. However, for this to work you need the Distributed Transaction Coordinator running (for SQL Servers). Also, SQL Server 2005 and above has the ability to start a transaction as a regular transaction and promote it to a distributed transaction if it needs to, whereas SQL 2000 will start all of them as distributed transactions because it doesn't have the ability to promote them.

在嵌套事务,整个交易不提交,直到最外层的事务被提交。

When you have nested transactions, the whole transaction doesn't commit until the outer-most transaction is committed.

下面的一些更多的信息

看看TransactionScopeOption;这决定了嵌套事务如何与外部交易进行交互。

Take a look at TransactionScopeOption; that determines how the nested transaction interacts with outer transactions.

这篇关于TransactionScope的层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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