我继承了一个代码,该代码执行5个不同的存储过程,这些存储过程在后端进行更新,每个存储过程都有自己的事务对象。 我在事务范围对象中包装了所有5个sql事务,因为它们都需要同时提交或回滚,现在它抛出以下错误:
An exception of type 'System.Transactions.TransactionManagerCommunicationException'
occurred in applicationname.dll but was not handled in user code
Additional information: 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.
这是一个函数,只要代码命中,就抛出异常:
Protected Overridable Function GetParameters(ByRef inConnection As SqlClient.SqlConnection _
, ByVal inStoredProcedureName As String _
, ByVal inIncludeReturnValue As Boolean) As SqlClient.SqlParameter()
Return SqlHelperParameterCache.GetSpParameterSet(inConnection, inStoredProcedureName, inIncludeReturnValue)
End Function
本文解释了如何解决此问题:The transaction manager has disabled its support for remote/network transactions
但我不想在不了解问题的情况下启用这些选项。我不能在事务管理器中包装sqltransactions,或者这个问题正在发生,因为他们正在使用他们的连接?
- 更新1
我们的DBA现在启用了MSDTC,除了我调用WCF Web服务之外,它适用于所有调用。它现在只是抛出一个超时异常:
The operation has timed out
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The operation has timed out
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆栈追踪:
[WebException: The operation has timed out]
System.Net.HttpWebRequest.GetResponse() +8420880
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +234
[TimeoutException: The HTTP request to 'http://test/testValidationService/test.svc' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.]
System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) +7074108
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +16650152
System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) +388
[TimeoutException: The request channel timed out while waiting for a reply after 00:00:59.9843749. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +14579646
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +622
更新2
超时似乎是由锁定引起的。所以我在事务管理器中有一个事务,我认为事务将被忽略,因为Transactionscope是包装器,但显然我仍然必须提交或回滚单个事务,这似乎已经解决了这个问题。从我读到的,个人提交/回滚将被忽略,因为最后说将由transactionscope?是对的吗?有人可以对此有所了解吗?
答案 0 :(得分:3)
您使用的是哪个SQL Server版本?
在SQL Server 2005及更早版本中:
一旦打开与db的多个连接,就会发生DTC升级。
要防止升级,请在事务中的所有查询中使用相同的SqlConnection对象。
在SQL Server 2008及更高版本中:
有关详细信息,请参阅此问题。 TransactionScope automatically escalating to MSDTC on some machines?