Wednesday, June 28, 2006

TransactionScope + MSDTC + Windows 2000

For my data access unit tests, I am a huge fan of the new System.Transactions namespace in .NET 2.0.  Basically I can define my unit tests like this:

using System;

using NUnit.Framework;

using System.Transactions;

 

[TestFixture]

public class TestClass1

{

    private TransactionScope _tx;

 

    [Setup]

    public void SetUp()

    {

        _tx = new TransactionScope();

    }

 

    [TearDown]

    public void TearDown()

    {

        _tx.Dispose();

    }

 

    [Test]

    public void TestSaveSomeData()

    {

        //some code that inserts data into the database

    }

}

Without the TransactionScope above, we would end up with a bunch of junk data in the database.

What’s great about this method, is that – from the bottom layer – I can start a transaction, do all kinds of inserts/updates/deletes and even select from that data, and then roll the entire thing back when I’m done.  (Even in the event of failure).

What’s not so nice is that TransactionScope uses MSDTC (Microsoft Distributed Transaction Coordinator) behind the scenes.  This is fine locally as long as you have the service running on your machine.  But what if you try to do this on a database on another server?

In my case I was connecting to a Windows 2000 Server on the local network.  The MSDTC handshake was failing.  This was due to security settings built into Windows XP SP2.

I received enourmous help from Florin Lazar’s blog post: http://blogs.msdn.com/florinlazar/archive/2004/06/18/159127.aspx

I opened up Administrative Tools -> Component Services , right-clicked on My Computer and selected Properties.  Under the MSDTC tab, I clicked Security.  Then I enabled Inbound and Outbound connections, and set the authentication to “No Authentication Required”.  That last part is kind of confusing, but basically it’s required for pre-XP/2003 machines, such as NT or Windows 2000.

Now my transactions are running again.

Tuesday, July 11, 2006 5:40:57 AM (Central Standard Time, UTC-06:00)
Hi,
I am not able to find "security" button under MSDTC tab in Windows 2000 Server/Professional OS. Could you guide me where i can find "No Authentication required" option.
Thanks in advance.
- Pavan
Tuesday, July 11, 2006 7:30:48 AM (Central Standard Time, UTC-06:00)
These options were added in XP/2003, and they do not exist in 2000.

This was an added security feature, so you should be fine in Windows 2000. What's the problem?
Wednesday, August 30, 2006 10:22:02 AM (Central Standard Time, UTC-06:00)
Problem is the GUI for this settings does not exist at all in Windows 2000. And the settings seem not to exist either. However, Windows 2000 SP4 will block any network access to MSDTC. I am completely lost what you really did and how you really solved it Ben. If you just uninstalled Windows 2000 and installed Windows Server 2003 that would be a fair explanation but not very useful for me ;)
Wednesday, August 30, 2006 9:01:46 PM (Central Standard Time, UTC-06:00)
Diego-

Yes, as you point out, that doesn't exist in Windows 2000. The way that I fixed it was to go to MY computer (XP) and change it so that I could handshake with the server (WIN 2000).
Comments are closed.
Loan - Credit Cards - Money - United Specialties