Thursday, December 20, 2012

TranscationScope Vs DbTransaction


A transaction is an atomic operation, i.e a set so statements should get executed completely or get rollback completely. A typical example of a transactions in the Bank account example, debit X amount from account A and credit the X amount to account B, now if there is an issue between debiting from account A and crediting to account B the whole operation should be cancelled.

Transactions in the Entity Framework can be performed using 2 ways, using TranscationScope or by using DbTransaction. In this post we shall compare the 2 approaches.


TranscationScope
DbTransaction
Uses the System.Transactions Assembly
Uses the System.Data.Common Assembly
Uses the Distributed Transaction Coordinator (MSDTC) under the hood to perform the transaction.
Handles the transactions directly
Requires the Distributed Transaction Coordinator (MSDTC) service to be running in the Windows server
No dependency on Distributed Transaction Coordinator (MSDTC)
Can be used to perform transactions across heterogeneous resources at the same time, like 2 different SQL servers placed in 2 different locations.
Can be used to perform transactions on only a single Database at a time.

Search Flipkart Products:
Flipkart.com

No comments: