简体   繁体   English

如何在 SQL Server 上启用 MSDTC?

[英]How do I enable MSDTC on SQL Server?

Is this even a valid question?这甚至是一个有效的问题吗? I have a .NET Windows app that is using MSTDC and it is throwing an exception:我有一个使用 MSTDC 的 .NET Windows 应用程序,它抛出异常:

System.Transactions.TransactionManagerCommunicationException: Network access for Distributed Transaction Manager (MSDTC) has been disabled. System.Transactions.TransactionManagerCommunicationException:分布式事务管理器 (MSDTC) 的网络访问已被禁用。 Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool ---> System.Runtime.InteropServices.COMException (0x8004D024): The transaction manager has disabled its support for remote/network transactions.请使用组件服务管理工具在 MSDTC 的安全配置中为网络访问启用 DTC ---> System.Runtime.InteropServices.COMException (0x8004D024):事务管理器已禁用对远程/网络事务的支持。 (Exception from HRESULT: 0x8004D024) at System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& transactionIdentifier, OletxTransactionIsolationLevel& isolationLevel, ITransactionShim& transactionShim).... (来自 HRESULT 的异常:0x8004D024)在 System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& transactionIdentifier, OletxTransactionIsolationLevel&isolationLevel&translationLevel&IShimShimShim)....

I followed the Kbalertz guide to enable MSDTC on the PC on which the app is installed, but the error still occurs.我按照Kbalertz 指南在安装了该应用程序的 PC 上启用了 MSDTC ,但仍然出现错误。

I was wondering if this was a database issue?我想知道这是不是数据库问题? If so, how can I resolve it?如果是这样,我该如何解决?

Use this for windows Server 2008 r2 and Windows Server 2012 R2 用于Windows Server 2008 r2和Windows Server 2012 R2

  1. Click Start , click Run , type dcomcnfg and then click OK to open Component Services . 单击“ 开始” ,单击“运行” ,键入dcomcnfg ,然后单击“ 确定”以打开“ 组件服务”

  2. In the console tree, click to expand Component Services , click to expand Computers , click to expand My Computer , click to expand Distributed Transaction Coordinator and then click Local DTC . 在控制台树中,单击以展开“ 组件服务” ,单击以展开“ 计算机” ,单击以展开“ 我的电脑” ,单击以展开“ 分布式事务处理协调器” ,然后单击“ 本地DTC”

  3. Right click Local DTC and click Properties to display the Local DTC Properties dialog box. 右键单击“ 本地DTC” ,然后单击“ 属性”以显示“ 本地DTC属性”对话框。

  4. Click the Security tab. 单击“ 安全”选项卡。

  5. Check mark "Network DTC Access" checkbox. 选中“网络DTC访问”复选框。

  6. Finally check mark "Allow Inbound" and "Allow Outbound" checkboxes. 最后选中“允许入站”“允许出站”复选框。

  7. Click Apply , OK . 单击应用确定

  8. A message will pop up about restarting the service. 将弹出有关重新启动服务的消息。

  9. Click OK and That's all. 单击“ 确定” ,这就是全部。

Reference : https://msdn.microsoft.com/en-us/library/dd327979.aspx 参考: https//msdn.microsoft.com/en-us/library/dd327979.aspx

Note: Sometimes the network firewall on the Local Computer or the Server could interrupt your connection so make sure you create rules to "Allow Inbound" and "Allow Outbound" connection for C:\\Windows\\System32\\msdtc.exe 注意:有时本地计算机或服务器上的网络防火墙可能会中断您的连接,因此请确保为C:\\Windows\\System32\\msdtc.exe创建“允许入站”“允许出站”连接的规则

Do you even need MSDTC? 你甚至需要MSDTC吗? The escalation you're experiencing is often caused by creating multiple connections within a single TransactionScope. 您遇到的升级通常是由在单个TransactionScope中创建多个连接引起的。

If you do need it then you need to enable it as outlined in the error message. 如果确实需要它,则需要按照错误消息中的说明启用它。 On XP: 在XP上:

  • Go to Administrative Tools -> Component Services 转到“管理工具” - >“组件服务”
  • Expand Component Services -> Computers -> 展开组件服务 - >计算机 - >
  • Right-click -> Properties -> MSDTC tab 右键单击 - >属性 - > MSDTC选项卡
  • Hit the Security Configuration button 点击安全配置按钮

I've found that the best way to debug is to use the microsoft tool called DTCPing 我发现最好的调试方法是使用名为DTCPing的微软工具

  1. Copy the file to both the server (DB) and the client (Application server/client pc) 将文件复制到服务器(DB)和客户端(应用程序服务器/客户端PC)
    • Start it at the server and the client 在服务器和客户端启动它
    • At the server: fill in the client netbios computer name and try to setup a DTC connection 在服务器上:填写客户端netbios计算机名称并尝试设置DTC连接
    • Restart both applications. 重启两个应用程序
    • At the client: fill in the server netbios computer name and try to setup a DTC connection 在客户端:填写服务器netbios计算机名称并尝试设置DTC连接

I've had my fare deal of problems in our old company network, and I've got a few tips: 我在旧的公司网络中遇到了问题,我有一些提示:

  • if you get the error message "Gethostbyname failed" it means the computer can not find the other computer by its netbios name . 如果您收到错误消息“Gethostbyname failed”,则表示计算机无法通过其netbios名称找到其他计算机。 The server could for instance resolve and ping the client, but that works on a DNS level. 例如,服务器可以解析并ping客户端,但这可以在DNS级别上运行。 Not on a netbios lookup level. 不在netbios查找级别。 Using WINS servers or changing the LMHOST (dirty) will solve this problem. 使用WINS服务器或更改LMHOST(脏)将解决此问题。
  • if you get an error "Acces Denied", the security settings don't match. 如果出现“Acces Denied”错误,则安全设置不匹配。 You should compare the security tab for the msdtc and get the server and client to match. 您应该比较msdtc的安全选项卡,并使服务器和客户端匹配。 One other thing to look at is the RestrictRemoteClients value. 另一件需要注意的是RestrictRemoteClients值。 Depending on your OS version and more importantly the Service Pack, this value can be different. 根据您的操作系统版本以及更重要的Service Pack,此值可能不同。
  • Other connection problems: 其他连接问题:
    • The firewall between the server and the client must allow communication over port 135. And more importantly the connection can be initiated from both sites (I had a lot of problems with the firewall people in my company because they assumed only the server would open an connection on to that port) 服务器和客户端之间的防火墙必须允许通过端口135进行通信。更重要的是,可以从两个站点启动连接(我的公司中的防火墙人员遇到很多问题因为他们假设只有服务器会打开连接到那个港口)
    • The protocol returns a random port to connect to for the real transaction communication. 该协议返回一个随机端口以连接到实际的事务通信。 Firewall people don't like that, they like to restrict the ports to a certain range. 防火墙的人不喜欢这样,他们喜欢将端口限制在一定范围内。 You can restrict the RPC dynamic port generation to a certain range using the keys as described in How to configure RPC dynamic port allocation to work with firewalls . 您可以使用密钥将RPC动态端口生成限制到某个范围,如如何配置RPC动态端口分配以使用防火墙中所述

In my experience, if the DTCPing is able to setup a DTC connection initiated from the client and initiated from the server, your transactions are not the problem any more. 根据我的经验,如果DTCPing能够设置从客户端发起并从服务器启动的DTC连接,那么您的交易不再是问题。

Can also see here on how to turn on MSDTC from the Control Panel's services.msc. 还可以在此处查看如何从控制面板的services.msc打开MSDTC。

On the server where the trigger resides, you need to turn the MSDTC service on. 在触发器所在的服务器上,您需要打开MSDTC服务。 You can this by clicking START > SETTINGS > CONTROL PANEL > ADMINISTRATIVE TOOLS > SERVICES. 您可以通过单击开始>设置>控制面板>管理工具>服务来实现此目的。 Find the service called 'Distributed Transaction Coordinator' and RIGHT CLICK (on it and select) > Start. 找到名为“分布式事务处理协调器”的服务并右键单击(在其上并选择)>启动。

MSDTC must be enabled on both systems, both server and client. 必须在服务器和客户端两个系统上启用MSDTC。
Also, make sure that there isn't a firewall between the systems that blocks RPC. 此外,请确保阻止RPC的系统之间没有防火墙。
DTCTest is a nice litt app that helps you to troubleshoot any other problems. DTCTest是一个很好的小应用程序,可以帮助您解决任何其他问题。

@Dan, @担,

Do I not need msdtc enabled for transactions to work? 我是否不需要启用msdtc才能使事务有效?

Only distributed transactions - Those that involve more than a single connection. 仅分布式事务 - 涉及多个连接的事务。 Make doubly sure you are only opening a single connection within the transaction and it won't escalate - Performance will be much better too. 确保您只在交易中打开一个连接并且不会升级 - 性能也会好得多。

MSDTC can be configured with MsDtc PowerShell module, eg: MSDTC 可以使用 MsDtc PowerShell 模块进行配置,例如:

# Import the module
Import-Module -Name MsDtc

# Set the DTC config
$dtcNetworkSetting = @{
    DtcName                           = 'Local'
    AuthenticationLevel               = 'NoAuth'
    InboundTransactionsEnabled        = $true
    OutboundTransactionsEnabled       = $true
    RemoteClientAccessEnabled         = $true
    RemoteAdministrationAccessEnabled = $true
    XATransactionsEnabled             = $false
    LUTransactionsEnabled             = $true
}
Set-DtcNetworkSetting @dtcNetworkSetting

# Restart the MsDtc service
Get-Service -Name MsDtc | Restart-Service

Run on each of the machines that will be supporting the distributed transactions (ie where the MSDTC service is running).在支持分布式事务的每台机器上运行(即运行 MSDTC 服务的机器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在SQL Server 2014上启用MSDTC? - How to enable MSDTC on SQL Server 2014? 使用“ TransactionScope”时,应该在Web服务器或数据库服务器中启用MSDTC吗? - Should I enable MSDTC in webserver or Database server when using “TransactionScope”? Sql Server Service Broker如何与MSDTC进行交互 - How does Sql Server Service Broker interact with MSDTC 如何在SQL Server Express的本地实例上“唤醒” msdtc - How to “wake up” msdtc on local instance of SQL Server Express 如何启用 Microsoft SQL 帐户? - How do I enable Microsoft SQL account? 如何启用? 全文搜索已安装在SQL Server 2014 Enterprise Edition中,但未启用 - How do I enable? Full Text Search is installed in SQL Server 2014 Enterprise Edition but not enabled 如何使用ADO.NET和SQL Server启用嵌套事务? - How do I enable nested transactions with ADO.NET and SQL Server? 如何避免在LINQ 2 SQL中升级为MSDTC - How to avoid escalating to MSDTC in linq 2 sql 来自Premise SQL Server上的Azure链接的SQL Server-MSDTC异常 - Azure Linked SQL server from on Premise SQL Server - MSDTC exception 当我为数据库启用 CDC 时,表是否会自动启用 SQL Server 中的 CDC? - Do tables automatically enable for CDC in SQL Server when I enable it for Database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM