Sitecore Commerce 8: Transactions not working with MS DTC on remote SQL server

Reading Time: 3 minutes

We have developed small commerce solution last year for one of our clients. Everything was working nicely on our development machines. Adding products into cart was without any problem.

Problem

When we deployed solution to TEST environment we were starting to receive exceptions like these when adding new products into cart or creating new orders:

Executing action method “Sitecore.Commerce.Plugin.Orders.CommandsController.CreateOrder (Sitecore.Commerce.Plugin.Orders)” with arguments ([“System.Web.Http.OData.ODataActionParameters”]) – ModelState is Valid

ERROR System.Exception: Error processing block: CsInventory.block.updateitemavailability —> System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. —> System.Runtime.InteropServices.COMException: The MSDTC transaction manager was unable to pull the transaction from the source transaction manager due to communication problems. Possible causes are: a firewall is present and it doesn’t have an exception for the MSDTC process, the two machines cannot find each other by their NetBIOS names, or the support for network transactions is not enabled for one of the two transaction managers. (Exception from HRESULT: 0x8004D02B)

ERROR Pipeline completed with error
System.Exception: Error processing block: CsInventory.block.updateitemavailability —> System.Transactions.TransactionException: The operation is not valid for the state of the transaction.

In your case, you can also receive / see these kind of exceptions:

[SQL:block:addlistentities.Exception: The operation is not valid for the state of the transaction.]

[SQL:block:persistentity.Insert.Exception: The operation is not valid for the state of the transaction.]

Solution

These exceptions should not be present when you have Commerce Server and SQL Server on one machine like you have it on development machine for example. That’s why we haven’t encountered them previously neither.

Problem was on TEST environment where Commerce Server and SQL Server were separated on different VMs.

Sitecore is using Microsoft Distributed Transaction Coordinator (MSDTC) in Commerce Server for which you can find more information in below articles:

You have three options here how to resolve this problem:

  • If you are not using Azure SQL, Sitecore recommends to turn on MSDTC on all servers. See option a) below.
  • If you are using Azure SQL, you can disable transactions. See option b).
  • If you are using Azure SQL, you have also other option and that it to enable MS Azure SQL databases with Commerce Server. See more information in this KB article with title “Running Sitecore Commerce 8.2.1 with Microsoft Azure SQL databases “. Please note that, as it’s stated in the article, “Sitecore currently provides experimental support for Azure SQL and Sitecore Commerce 8.2.1 compatibility”.

Solution a) Enabling transactions

DTC should be enabled in the security configuration for MSDTC using the Component Services Administrative tool. You will need to enable MSDTC on all servers running Commerce Server, as well as the SQL Server unless SQL Server and Commerce Server are running on the same machine.

To enable DTC, please perform the following steps:

  1. Click Start > Run, type dcomcnfg, and then click OK to open Component Services.
  2. In the console tree, click to expand Component Services, click to expand Computers, click to expand My Computer, and then click to expand Distributed Transaction Coordinator.
  3. Right-click Local DTC, and then click Properties to display the Local DTC Properties dialog box.
  4. Click the Security tab.
  5. In the Security Settings section, click Network DTC Access.
  6. In the Client and Administration section, select Allow Remote Clients and Allow Remote Administration.
  7. In the Transaction Manager Communication section, select Allow Inbound and Allow Outbound.
  8. In the Transaction Manager Communication section, select Mutual Authentication Required, and select Incoming Caller Authentication Required if you are running MSDTC in a cluster. No Authentication Required is the recommended selection.
  9. Select Enable XA Transactions, and then click OK.
  10. Repeat steps 1 through 9 on the other Web servers.

You can also read similar step by step guideline also with some pictures here.

Use DTCPing.exe to validate the connection between the Web server and the computer that is running SQL Server or an SQL cluster depending on your configuration. To obtain the DTCPing.exe tool, go to http://go.microsoft.com/fwlink/?LinkId=72166.

For more information about how to troubleshoot MSDTC, go to http://go.microsoft.com/fwlink/?LinkId=72203 https://blogs.msdn.microsoft.com/asiatech/2011/03/01/how-to-troubleshoot-msdtc-communication-failure-ii/

Also, please take a look at the following articles regarding enabling DTC: https://msdn.microsoft.com/en-us/library/dd327979.aspx

Solution b) Disabling transactions

You can also disable transactions by setting this in json config for COmmerce Engine:

{ "$type":  "Sitecore.Commerce.Core.TransactionsPolicy, Sitecore.Commerce.Core",
     "TransactionalityEnabled":  false
}

Happy coding!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.