Enabling XA Transactions in Windows SQL Server Database

You can enable XA transactions in Windows SQL Server database and run Windows Distributed Transaction Coordinator (MSDTC) Service by following the instructions for your operating system.

This task shows you how to:

Enable XA Distributed Transactions and Configure MSDTC Service for XA Transactions on Windows

  1. Launch and connect SQL Server Management Studio or use the sqlcmd utility.
  2. Execute this stored procedure on master database EXEC sp_sqljdbc_xa_install.
  3. Click Start, type dcomcnfg in the Start Search box, and then press Enter to open Component Services.

    Tip: You can also type %windir%\system32\comexp.msc in the Search box to open Component Services.

  4. In the Console Root tree, expand Component Services > Computers > My Computer and click Distributed Transaction Coordinator
  5. Right-click Local DTC and then select Properties.
  6. In the Local DTC Properties dialog box that appears, click the Security tab.
  7. Select Enable XA Transactions, and then click OK. This action causes an MS DTC service restart.
  8. Click OK again to close the Properties dialog box, and then close Component Services.
  9. Stop and then restart SQL Server to make sure that it syncs with the MS DTC changes.

Result: For more information, see https://docs.microsoft.com/en-us/sql/connect/jdbc/understanding-xa-transactions?view=sql-server-ver15.

Enable XA Distributed Transactions and Configure MSDTC Service for XA Transactions onon Linux

  1. Launch and connect SQL Server Management Studio or use the sqlcmd utility.
  2. Execute this stored procedure on master database EXEC sp_sqljdbc_xa_install.
  3. Configure the RPC and MSDTC ports:
    • Use mssql-conf to set the network.rpcport value. The following example sets it to 13500:

      sudo /opt/mssql/bin/mssql-conf set network.rpcport 13500

    • Set the distributedtransaction.servertcpport value. The following example sets it to 51999:

      sudo /opt/mssql/bin/mssql-conf set distributedtransaction.servertcpport 51999

    • Restart SQL Server:

      sudo systemctl restart mssql-server

  4. Configure the firewall to allow communication on servertcpport and port 135. This action enables the RPC endpoint-mapping process and MSDTC process to communicate externally to other transaction managers and coordinators. Run the following commands:

    sudo firewall-cmd --zone=public --add-port=51999/tcp --permanent
    sudo firewall-cmd --zone=public --add-port=135/tcp --permanent
    sudo firewall-cmd –reload

  5. Configure the Linux server routing table so that RPC communication on port 135 is redirected to SQL Server's network.rpcport. Run the following commands:

    sudo firewall-cmd --permanent --add-forward-port=port=135:proto=tcp:toport=13500
    sudo firewall-cmd –reload

  6. At this point, SQL Server should be able to participate in distributed transactions. To verify that SQL Server is listening, run the netstat command. (You might have to first install the net-tools package.)

    sudo netstat -tulpn | grep sqlservr

    You should see output similar to the following:

    tcp 0 0 0.0.0.0:1433 0.0.0.0:* LISTEN 13911/sqlservr
    tcp 0 0 127.0.0.1:1434 0.0.0.0:* LISTEN 13911/sqlservr
    tcp 0 0 0.0.0.0:13500 0.0.0.0:* LISTEN 13911/sqlservr
    tcp 0 0 0.0.0.0:51999 0.0.0.0:* LISTEN 13911/sqlservr
    tcp6 0 0 :::1433 :::* LISTEN 13911/sqlservr
    tcp6 0 0 ::1:1434 :::* LISTEN 13911/sqlservr
    tcp6 0 0 :::13500 :::* LISTEN 13911/sqlservr
    tcp6 0 0 :::51999 :::* LISTEN 13911/sqlservr

  7. Restart the SQL server by running the following command:

    sudo systemctl restart mssql-server
    Note: After a restart, SQL Server does not start listening on the servertcpport until the first distributed transaction. In this case, you would not see SQL Server listening on port 51999 in this example until the first distributed transaction.

Result: For more information, see https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-msdtc?view=sql-server-ver15.