7.1. Using Distributed Transactions
Problem
You need to create a distributed transaction—a transaction that spans two or more data sources.
Solution
Use the TransactionScope class within the System.Transactions namespace.
The solution uses a table named SystemTransaction in the AdoDotNet35Cookbook database. Create the database in the AdoDotNet35Cookbook database in both SQL Server and SQL Server Express instances by executing the following T-SQL statement.
USE AdoDotNet35Cookbook GO CREATE TABLE SystemTransaction( Id int NOT NULL PRIMARY KEY, Field1 nvarchar(50) NULL, Field2 nvarchar(50) NULL )
Tip
You need to configure the Microsoft Distributed Transaction Coordinator (MS DTC) in Windows to let applications enlist resources in a distributed transaction.
Follow these steps to fully enable MS DTC:
Select Control Panel→Administrative Tools→Component Services to open the Component Services dialog.
Expand Console Root→Component Services→Computers→My Computer in the tree view.
Right-click My Computer and select Properties from the context menu.
Select the MSDTC tab in the My Computer Properties dialog.
Click the Security Configuration button to open the Security Configuration dialog.
Ensure that all of the checkboxes are checked.
Ensure that the DTC Logon Account name is NT Authority\NetworkService.
Click OK to close the Security Configuration dialog.
Click OK to close the My Computer Properties dialog.
Close the Component Services dialog.
The solution successfully inserts a record into the SystemTransaction ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access