Thursday, July 8, 2010

MSDTC-Transaction Controller


On writing an .NET application with multiple LINQ insert/update statements TransactionScope is useful.
Letz say we are inserting EmployeeInfo table, then EmployeeSalaray table, followed by EmployeeAttendance table.
When the application completes all work it wants to perform in a transaction, Complete method informs transaction manager that it is acceptable to commit the transaction. Failing to call this method aborts the transaction. Isn't it cool?

But, I got an error '[System.Transactions.TransactionManagerCommunicationException] during TransactionScope execution. On analysis, it has been found Network access for Distributed Transaction Manager (MSDTC) has been disabled by default in XP. MSDTC is a transaction manager which permits client applications to include several different sources of data in one transaction, and which then coordinates committing the distributed transaction across all the servers that are enlisted in the transaction.

To resolve this issue, MSDTC is enabled via 'Control Panel->Administrative Tools->ComponentServices->MyComputer' MSDTC properties. You need to click on Security Configuration button under Transaction Configuration panel. In that section, enable 'Network DTC Access' After this setup, my application runs smoothly and TransactionScope is successful.

4 comments:

  1. MSDTC is good for scenarios where we need to connect to two different datasources. But for the tables/databases of same type and which exists in the same machine we can go for DataClassesDataContext.

    Ref:http://chiragrdarji.wordpress.com/2007/08/25/how-to-use-transaction-in-linq-using-c/

    ReplyDelete
  2. Srini, thanx for the info. Tried the base class DbConnection. Still it needs MSDTC process for distributed DB

    ReplyDelete
  3. Microsoft has implemented Transactions even for as Single Datasource using DTC in SSIS.

    Sample Scenario : Containers in SSIS wont work if DTC is not enabled. it will generate a error as u faced

    ReplyDelete