Thursday, November 13, 2008

Configuring MS DTC on WinXP, Server 2003, and Server 2008 machines

Our N-Tier ASP.NET (C# 2008 / SQL Server)  application uses MS DTC transactions for database integrity. This allows a transaction to embrace several BL or DL method calls without sharing the same database connection.
A usage is simple:

using System.Transactions; 

using (TransactionScope myTransactionScope = new TransactionScope()) {
  // Do any database related work you need: call methods, open and close connections, update multiple tables.
  // Database integrity is preserved  even if one of methods which update database fails.


To support MS DTC all servers which run our application (including developers' machines) and servers which host a databases were properly configured. (Configuring developers' machines allowed to work properly with your local copy of application and with a remote database.

1) To configure DTC on Windows XP, Windows Server 2003 machine follow these instructions to open Component Services window and configure DTC.
Make sure that "Use local coordinator" check box is checked on MSDTC tab of computer properties window.
Make sure that "Network DTC access" is checked on MSDTC=>Security Configuration window, that both "Allow Inbound" and "Allow Outbound" are checked, and DTC Logon Account is set to "NT AUTHORITY\NetworkService".
2) On Windows Server 2008 machine it's pretty much the same, except that in Component Services window has My Computer -> Distributed Transaction Coordinator -> Local DTC node, on which you'll need to right-click and choose Properties.
3) After configuring DTC restart your machine.
4) Open Control Panel -> Administrative Tools -> Services and make sure that DTC is set to start automatically and is started.

Reference on using DTC with N-Tier application: