异常"操作是无效的交易&QUOT的状态;使用的TransactionScope [英] Exception "The operation is not valid for the state of the transaction" using TransactionScope

查看:892
本文介绍了异常"操作是无效的交易&QUOT的状态;使用的TransactionScope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们对服务器#1的Web服务和服务器#2的数据库。
Web服务使用事务范围产生分布式事务。一切都是正确的。

We have a web service on server #1 and a database on server #2. Web service uses transaction scope to produce distributed transaction. Everything is correct.

和我们有服务器3#另一个数据库。我们有一些问题,在此服务器上重新安装我们的操作系统和软件。我们配置MSDTC并试图利用Web服务从服务器#1此服务器上与数据库通信。
现在经过交易范围,我们得到内第一个select语句:的操作是无效的事务的状态。如果使用事务范围,每个Web服务请求此异常下降。
服务器#2,服务器#3几乎是相似的。所不同的可能是只设置。
的.NET framework 3.5 SP1安装和SQL Server SP3的所有服务器上

And we have another database on server #3. We had some problems with this server and we reinstalled operation system and software. We configured MSDTC and tried to use web service from server #1 to communicate with database on this server. And now after first select statement within transaction scope we get: The operation is not valid for the state of the transaction. This exception falls in every web service request if it is using transaction scope. Server #2 and Server #3 is almost similar. The difference can be only in settings. .NET framework 3.5 SP1 installed and SQL Server SP3 on all servers.

展开堆栈跟踪:

System.Transactions.TransactionState.EnlistPromotableSinglePhase(InternalTransaction
TX,IPromotableSinglePhaseNotification
promotableSinglePhaseNotification,交易原子事务)в
System.Transactions.Transaction .EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification
promotableSinglePhaseNotification)в
System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(交易
TвSystem.Data.SqlClient.SqlInternalConnection.Enlist(事务Tв
系统。 Data.SqlClient.SqlInternalConnectionTds.Activate(交易
交易)в
System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(交易
交易)в
System.Data.ProviderBase.DbConnectionPool。的getConnection(的DbConnection
owningObject)в
System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection
owningConnection)в
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection
outerConnection,DbConnectionFactory connectionFactory的)в
System.Data.SqlClient.SqlConnection.Open()в
NHibernate.Connection.DriverConnectionProvider.GetConnection()в
NHibernate.Impl.SessionFactoryImpl.OpenConnection()

System.Transactions.TransactionState.EnlistPromotableSinglePhase(InternalTransaction tx, IPromotableSinglePhaseNotification promotableSinglePhaseNotification, Transaction atomicTransaction) в System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification) в System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction t в System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction t в System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction) в System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction) в System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) в System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) в System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) в System.Data.SqlClient.SqlConnection.Open() в NHibernate.Connection.DriverConnectionProvider.GetConnection() в NHibernate.Impl.SessionFactoryImpl.OpenConnection()

我搜索了这个消息,但并没有找到任何合适的解决方案。
那么,什么设置我应该检查什么究竟,我应该做些什么来解决呢?

I searched this message but didn't found any appropriate solution. So what settings should I check and what exactly should I do to fix it?

推荐答案

Lanfear,我来了在相同的错误消息,我找到了解决办法。您的情况可能会有所不同,但我希望下面的知识将是对你有用。

Lanfear, I have come across the same error message and I found a solution. Your situation may be different, but I hope that the following knowledge will be useful to you.

System.Transactions.Transaction.Current.TransactionInformation。状态将返回当前事务的状态。

System.Transactions.Transaction.Current.TransactionInformation.Status will return the status of the current transaction.

在哪里异常与消息抛出的每个案件操作是无效的交易,当我踏上直通与调试,我看到的状态为已中止引发的异常前的状态。

In each case where an exception is thrown with the message The operation is not valid for the state of the transaction, when I step thru with the debugger, I see that the status is "Aborted" before the exception is thrown.

在我的情况下,这个问题是由嵌套两笔交易对方内线,并错误地中止引起了双方当我想放弃唯一的一个。很显然,如果你使用的TransactionScope 默认的构造函数新的TransactionScope()有两个嵌套事务,中止内部交易中止外部事务也是如此。解决的办法是使用构造新的TransactionScope(TransactionScopeOption.RequiresNew)使用此构造,内部交易将是一个新的事务,并中止它不会中止外部事务。

In my case, the problem was caused by nesting two transactions inside each other and mistakenly aborting both when I wanted to abort only one. Apparently, if you use the TransactionScope default constructor New TransactionScope() with two nested transactions, aborting the inner transaction aborts the outer transaction as well. The solution is to use the Constructor New TransactionScope(TransactionScopeOption.RequiresNew) Using this constructor, the inner transaction will be a new transaction and aborting it will not abort the outer transaction.

这解决了我的问题。

这篇关于异常"操作是无效的交易&QUOT的状态;使用的TransactionScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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