Have you ever seen an issue related to MS DTC, SQL Server and JDBC XA distributed transactions? A client contacted me for help and he wanted my opinion within one hour. They signed up for my On Demand consulting services and we started looking at the server and application.
They showed me the error in their application which was as below
Caused by: javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Failed to enlist. Error: “Import of Microsoft Distributed Transaction Coordinator (MS DTC) transaction failed: 0x8004d00e(XACT_E_NOTRANSACTION).”
I asked them to show SQL ERRORLOG to see if there are some DTC related messages.
2017-08-20 09:47:16.76 spid78 Attempting to load library ‘SQLJDBC_XA.dll’ into memory. This is an informational message only. No user action is required.
2017-08-20 09:47:16.77 spid78 Using ‘SQLJDBC_XA.dll’ version ‘0004.00.2206’ to execute extended stored procedure ‘xp_sqljdbc_xa_start’. This is an informational message only; no user action is required.
2017-08-20 09:47:21.45 spid77 Attempting to initialize Microsoft Distributed Transaction Coordinator (MS DTC). This is an informational message only. No user action is required.
2017-08-20 09:47:23.95 spid77 Recovery of any in-doubt distributed transactions involving Microsoft Distributed Transaction Coordinator (MS DTC) has completed. This is an informational message only. No user action is required.
2017-08-20 09:47:23.96 spid77 Error: 8509, Severity: 16, State: 1.
2017-08-20 09:47:23.96 spid77 Import of Microsoft Distributed Transaction Coordinator (MS DTC) transaction failed: 0x8004d00e(XACT_E_NOTRANSACTION).
Every time we tried XA transaction from application, it caused error 8509 in ERRORLOG.
Here are a few more details about the environment which you may want to match before implementing:
- Clustered Instance of SQL Server.
- Separate group for MSDTC resource in cluster.
DTC Settings were OK. Below is the checklist
- Go to “Administrative Tools > Component Services” (or Start > Run > DcomCnfg > Enter)
- On the left navigation tree, go to “Component Services > Computers > My Computer> Distributed Transaction Coordinator > Clustered DTCs “
- Right click on the DTC service for this SQL Server group and select “Properties”.
- Go to the security tab and check “Network DTC Access”, “Allow Inbound”, and “Allow Outbound”.
Since it was a clustered DTC, the next thing which came to my mind was DTC and SQL mapping in the cluster. I looked up at various resources and found the solution.
Here are the three commands I used to fix the mapping.
- View the mapping
msdtc -tmmappingview *
- Clear the mapping.
msdtc.exe -tmMappingClear -name DTC_INST02_Mapping
- Create correct mapping
Msdtc -tmMappingSet -name DTC_INST02_Mapping -service "MSSQL$INST02" -ClusterResourceName "MSDTC-INST02"
Do you need a DTC If you are not using SQL JDBC XA? You do not need to set TM mappings. SQL 2008 Server knows which clustered DTC instance, it needs to use. Since TM mappings are stored in the cluster registry which is shared across all nodes, we can set them at from any of the cluster nodes.
Reference: Pinal Dave (https://blog.sqlauthority.com)