Cari Blog Ini

02 Juli 2012

Examples of Using MS DTC - Microsoft Distributed Transaction Coordinator - 02

In this section, we'll look at two Real World examples
that demonstrate how the coordination services of MS DTC
are critical when distributed transactions are used.
These examples show what can happen
if some transactions in a distributed transaction succeed and others fail.


* REAL WORLD   Bank Transactions

Suppose you are choosing a way in which computer systems at two banks
perform transactions when money is transferred between the banks.
Two basic transactions must be performed by these systems
when a customer requests an electronic transfer: money must be removed
from account 1 at bank A and added to account 2 at bank B.




How does this electronic transfer happen?
If both accounts were at the same bank,
this transfer could be performed by simply updating data in the database on one system.
But because the accounts in our example are at different banks,
the transfer involves initiating a remote transaction.
The transaction, which comprises two transactions,
can be initiated by either of the two systems involved in the transaction,
or it can be initiated by a third system (a client system).




These two transactions can be executed by a teller initiating a program
that runs a series of SQL statements on the third (client) computer system.
These SQL statements perform the following operations:

1. Update account 1 on system A by removing n dollars
2. Commit transaction
3. Update account 2 on system B by adding n dollars
4. Commit transaction

This technique will work as long as no problems occur on any of the systems,
but it is not a safe way to transfer money.
What would happen if one of the systems fails during these operations?
The following results could occur:


The first transaction fails because of an error on either system A or the client system.
The second transaction is thus not performed, so no money is transferred.
The first transaction succeeds,
but the second fails because of an error on either system B or the client system.
The money is lost.
The second result is certainly not an acceptable option.

Here's a better way of conducting this transaction:

1. Update account 1 on system A by removing n dollars.
2. Update account 2 on system B by adding n dollars.
3. Commit both transactions as a set. Either both commit or neither commits.

MS DTC enables you to perform these operations.
By using the MS DTC service, you can specify which distributed transactions are committed as a set.
These transactions will either all commit or all be rolled back.



Source: Microsoft SQL Server 2000 Administrator's Companion Book