Working with Distributed Transactions
In Chapter 4, we learned about the ADO.NET SqlTransaction class. You can use a SqlTransaction object to group the results of multiple queries on a connection as a single unit of work.
Let’s say that your database contains banking information. You can transfer money from a savings account to a checking account by executing the following two queries:
UPDATE Savings SET BalanceDue = BalanceDue – 100 WHERE AccountID = 17 UPDATE Checking SET BalanceDue = BalanceDue + 100 WHERE AccountID = 17
To make sure you can group the two changes into a single unit of work that you can commit or roll back, you can create a new SqlTransaction object before executing the queries. If an error occurs or one of the queries doesn’t ...
Get Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.