O'Reilly logo

Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition by David Sceppa

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required