Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

SQL Server linked server error 7391: OLE DB provider was unable to begin a distributed transaction

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

A query or procedure that uses a linked server fails with error 7391. Microsoft's message text is: The operation could not be performed because OLE DB provider "%ls" for linked server "%ls" was unable to begin a distributed transaction. In the real message, the two placeholders show the provider and linked server names. You may also see error 8522, "Microsoft Distributed Transaction Coordinator (MS DTC) has stopped this transaction."

The read-only checks below take minutes and cover both servers. The one change to DTC settings restarts the DTC service, so it comes with a warning and a way back.

What the error means

Microsoft's page says: "This error occurs because the Microsoft Distributed Transaction Coordinator (MSDTC) service isn't running or has disabled network access." A statement that touches a remote server inside a transaction needs MSDTC on both ends to start the transaction across the network. If either end cannot, the provider reports that it could not begin a distributed transaction.

The older Microsoft support page for the provider message gives the same cause. It describes the case in which you try "to start a distributed transaction between linked servers that are running Windows Server". It says the behaviour occurs if the DTC service is disabled or network DTC access is disabled, and that "By default, network DTC access is disabled in Windows Server."

Two further points from the error page. Error numbers from 7300 to 7399 "indicate a problem that affects the provider", so the message can be incomplete. And if you get 7391 from replication or SSIS, the code may contain a BEGIN DISTRIBUTED TRAN statement.

Likely causes

Cause What you see How to confirm
MSDTC not running, or network access disabled, on one or both servers Error 7391, sometimes 8522 The DTC network settings on each server, below
Names do not resolve between the servers The servers can reach each other by IP address but not by name, or in one direction only Test name resolution in both directions
RPC ports blocked by a firewall A firewall sits between the servers and the RPC ports are not open Firewall rules for RPC between the servers
The driver does not support distributed transactions, or the linked server points back to the first server (loopback) The error continues even when DTC settings are correct Ask the driver vendor. Microsoft says loopback linked servers "aren't supported for many operations, such as distributed transactions"
@@SERVERNAME does not match the computer name The name SQL Server reports differs from the Windows computer name Compare the two values on each server
Clustered servers where MSDTC has no IP address of its own One or more of the servers is on a Windows Server Failover Cluster Microsoft says the MSDTC service on the cluster "must have its own IP address"

Prove the cause before changing anything

All of these read only. Do them on both servers.

  1. Read the DTC network and security settings. Microsoft's Get-DtcNetworkSetting page says the cmdlet "gets the Distributed Transaction Coordinator (DTC) network and security configuration settings for a DTC instance":
Get-DtcNetworkSetting -DtcName "Local"

The page's example output lists AuthenticationLevel, InboundTransactionsEnabled, LUTransactionsEnabled, OutboundTransactionsEnabled, RemoteAdministrationAccessEnabled, RemoteClientAccessEnabled and XATransactionsEnabled. Copy the full output for each server into your change record.

  1. Check that the DTC service is running on each server. The error page says to start it on "all servers that are involved in the distributed transaction".
  2. Check name resolution in both directions. The page says the servers must communicate "by name and not only by IP address", from server A to server B and from B to A, and that you should resolve all name resolution problems before you run the query.
  3. Ask whether a firewall sits between the servers. The page says to make sure your RPC ports are open and points to Microsoft's pages on RPC dynamic port allocation with firewalls, firewalls for AD domains and trusts, and the Windows Firewall for SQL Server.
  4. Run SELECT @@SERVERNAME; on each server and compare it with the computer name. Microsoft says: if it does not match, rename the server.
  5. If the linked server object is a view or a stored procedure, or a trigger runs, check whether it points to a third server. The page says that if so, "the third server is the source of the problem".
  6. For a fuller provider message, Microsoft says to run DBCC TRACEON (3604, 7300) before the query. The error page does not say how long that setting lasts. Microsoft's trace flags page says a flag enabled at session level "never affects another session" and that its effect is lost when the session signs out, so run it in the same session as the query and without the -1 argument.

Example (illustrative): at contoso.com.au a procedure on sql01 updates a table on sql02 through a linked server and fails with 7391 and 8522. Get-DtcNetworkSetting on sql02 shows InboundTransactionsEnabled as False. The other six checks are clean. That points to DTC network access on sql02.

Fix

Fix the cause you found. If it is a name, firewall, loopback or rename problem, correct that first, because changing DTC will not help. Microsoft's page also says to set XACT_ABORT to ON for data modification statements against most OLE DB providers, with SET XACT_ABORT ON, unless the provider supports nested transactions. That is a change to the code that runs the query, not to the server.

DTC network access disabled

Microsoft's provider page says to enable network DTC access on both servers, then stop and restart the DTC service, then restart "any resource manager services that participates in the distributed transaction (such as Microsoft SQL Server or Microsoft Message Queue Server)". Its wizard steps (Control Panel, Add or Remove Programs, Application Server) describe an older Windows Server. For current servers, the cmdlet below is Microsoft's documented way to change DTC network settings. Microsoft's pages do not state which of its parameters matches the older "Enable network DTC access" check box.

Save the output of the first command in step 1 for the server you are about to change. It is the only record of the starting values.

Disruptive step: The next command changes the DTC network settings on this server and restarts the DTC instance. Microsoft's cmdlet page says it "also restarts the DTC instance". Anything on this server that uses DTC is affected while it restarts. Opening inbound, outbound and remote client access also widens what this server accepts from the network, so do it only on servers that need distributed transactions.

Run this on the server whose settings you saved, one server at a time. The three parameters below are a choice for a design that needs transactions to flow in, flow out and be started by remote clients. That choice is advice, not a mapping Microsoft documents. All three belong to the cmdlet's Network Settings parameter set, so they can be combined. Leave AuthenticationLevel at the saved value unless you have a reason to change it:

Set-DtcNetworkSetting -DtcName "Local" -InboundTransactionsEnabled $True -OutboundTransactionsEnabled $True -RemoteClientAccessEnabled $True

To undo it: run Set-DtcNetworkSetting -DtcName "Local" again, with each parameter set to the value you saved, for example -InboundTransactionsEnabled $False if it was False. This restarts DTC again.

If the error page's list still fits after this, the remaining Microsoft steps are described without commands: restart the resource manager services if the older page's instructions apply to your setup, which restarts SQL Server and needs a maintenance window; give a clustered MSDTC its own IP address with name resolution; set remote proc trans to OFF if you use the older remote servers technology; and make sure the SQL Server startup account has full control on the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServer.

Confirm the fix

  • Run the statement that failed. It completes with no 7391 or 8522.
  • Run Get-DtcNetworkSetting -DtcName "Local" again on both servers. The values match what you chose.
  • Name resolution still works in both directions.

What to watch afterwards

  • Whether the error returns after a server rename, rebuild or restore, when DTC settings may be reset to their defaults.
  • Whether a new firewall rule or a network change closes the RPC ports.
  • For a cluster, after each failover.

Risks and limits

These steps have not been run or lab-tested. Microsoft's error page names "SQL Server" with no version range. The OLE DB provider page describes a procedure for an older Windows Server and gives no steps for current versions. Microsoft's Set-DtcNetworkSetting page does not say which of its parameters correspond to that procedure, and its own example output does not match its command. Choose the parameters for your design and compare the result with the values you saved. The -DisableNetworkAccess switch is a different parameter set and is not part of this fix.

Sources