同一个TransactionScope中不能操作两个及其以上的DATABASE

来源:互联网 发布:国产开源软件 编辑:程序博客网 时间:2024/05/02 01:41

最近用LINQ TO SQL,有些事情是需要原子性操作的,因此就用了一下事务,即TransactionScope。

但是在使用中发现如下的一个错误,查了很多资料才解决,在此分享一下:

Network access for Distributed Transaction Manager (MSDTC) has been disabled. 
Please enable DTC for network access in the security configuration for MSDTC 
using the Component Services Administrative tool. InnerException: 
System.Runtime.InteropServices.COMException (0x8004D024): The transaction 
manager has disabled its support for remote/network transactions. (Exception 
from HRESULT: 0x8004D024)
   at System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 
propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& 
transactionIdentifier, OletxTransactionIsolationLevel& isolationLevel, 
ITransactionShim& transactionShim)
   at 
System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropiga
tionToken(Byte[] propagationToken)




Communication with the underlying transaction manager has failed. 
InnerException: System.Runtime.InteropServices.COMException (0x8004D02B): The 
MSDTC transaction manager was unable to pull the transaction from the source 
transaction manager due to communication problems. Possible causes are: a 
firewall is present and it doesn't have an exception for the MSDTC process, the 
two machines cannot find each other by their NetBIOS names, or the support for 
network transactions is not enabled for one of the two transaction managers. 
(Exception from HRESULT: 0x8004D02B)
   at System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 
propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& 
transactionIdentifier, OletxTransactionIsolationLevel& isolationLevel, 
ITransactionShim& transactionShim)
   at 
System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropiga
tionToken(Byte[] propagationToken)



开始以为和MSDTC服务有关,在网上搜索了相关资料并按照其设置之后,问题依旧。

以后发现问题的原因在于在同一个TransactionScope里面,试图操作两个不同的DATABASE导致的,把其中一个数据库操作提出来即可……