当我尝试打开下面代码中的第二个连接时,我看到以下错误:分布式事务管理器(MSDTC)的网络访问已被禁用。请使用组件服务管理工具在MSDTC的安全配置中为网络访问启用DTC。
Public Function Test()
Using Scope = New TransactionScope
getMailServer()
getMailServer()
End Using
End Function
Private Function getMailServer() As String
Dim objCommand As SqlCommand, objCommand2 As SqlCommand
Dim objCon As SqlConnection
Dim intDeleteCount As Integer
Dim objDR As SqlDataReader
Dim strServer As String
Try
objCommand = New SqlCommand
objCommand2 = New SqlCommand
objCon = New SqlConnection(_ConString) 'taken from web.config
objCon.Open()
objCommand.Connection = objCon
Using objCon
Using objCommand
objCommand2.Connection = objCon
objCommand2.CommandText = "SELECT SMTPServer FROM dbServer"
objDR = objCommand2.ExecuteReader
Do While objDR.Read
strServer = objDR("SMTPServer")
Loop
objDR.Close()
End Using
End Using
Return strServer
Catch ex As Exception
Throw
Finally
End Try
End Function请注意,我花了一些时间谷歌这个,我已经尝试了这个网站上张贴的一些事情,例如重新启动服务中的分区事务协调器。我还在某处读到,分布式事务(具有多个连接对象的事务)应该避免使用TransactionScope。我不确定这是不是真的。
发布于 2013-01-26 07:01:59
您可以将TransactionScope用于分布式事务。事实上,通过在.NET 2.0中引入TransactionScope,微软让COM+走出了困境。这是一个非常好的举动,COM+太糟糕了。
您需要在参与事务的所有计算机上配置DTC以进行网络访问-运行代码的计算机,以及运行数据库(或您可能正在使用的其他资源,如MSMQ)的计算机。
这是how to enable DTC network access。
https://stackoverflow.com/questions/14531660
复制相似问题