title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | |||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Create a distributed transactions |
Applications can use MSDTC to extend or distribute a transaction across several instances of SQL Server. A .NET class can also distribute a transaction. |
markingmyname |
maghan |
05/13/2019 |
sql |
native-client |
reference |
|
[!INCLUDE SQL Server]
Important
[!INCLUDEsnac-removed-oledb-and-odbc]
A distributed transaction can be created for different Microsoft SQL systems in different ways.
The Microsoft Distributed Transaction Coordinator (MSDTC) allows applications to extend or distribute a transaction across two or more instances of [!INCLUDEssNoVersion]. The distributed transaction works even when the two instances are hosted on separate computers.
MSDTC is installed for Microsoft SQL Server on-premises, but isn't available for Microsoft's Azure SQL Database cloud service.
MSDTC is called by the SQL Server Native Client driver for Open Database Connectivity (ODBC), when your C++ program manages a distributed transaction. The Native Client ODBC driver has a transaction manager that is compliant with the Open Group Distributed Transaction Processing (DTP) XA standard. This compliance is required by MSDTC. Typically, all transaction management commands are sent through this Native Client ODBC driver. The sequence is as follows:
-
Your C++ Native Client ODBC application starts a transaction by calling SQLSetConnectAttr, with the autocommit mode turned off.
-
The application updates some data on SQL Server X on computer A.
-
The application updates some data on SQL Server Y on computer B.
- If an update on SQL Server Y fails, all the uncommitted updates on both SQL Server instances are rolled back.
-
Finally, the application ends the transaction by calling SQLEndTran (1), with either the SQL_COMMIT or SQL_ROLLBACK option.
(1) MSDTC can be invoked without ODBC. In such a case, MSDTC becomes the transaction manager, and the application no longer uses SQLEndTran.
Suppose that your C++ Native Client ODBC application is enlisted in a distributed transaction. Next the application enlists in a second distributed transaction. In this case, the [!INCLUDEssNoVersion] Native Client ODBC driver leaves the original distributed transaction, and enlists in the new distributed transaction.
For more information, see DTC Programmer's Reference.
MSDTC isn't supported for either Azure SQL Database or Azure Synapse Analytics.
However, a distributed transaction can be created for SQL Database by having your C# program use the .NET class System.Transactions.TransactionScope.
The following other programming languages might not provide any support for distributed transactions with the SQL Database service:
- Native C++ that use ODBC drivers
- Linked server using Transact-SQL
- JDBC drivers