Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

DTC Error with NServiceBus and Linq To Sql August 31, 2010

Filed under: Error,Linq to Sql,NServiceBus — Rupert Bates @ 8:08 pm

I spent most of the morning debugging the following error which I got when using Linq To Sql with NServiceBus:

The transaction has already been implicitly or explicitly committed or aborted

This occurred whenever I tried to do any data access from within a service running in the NServiceBus generic host, and confused the hell out of me because I knew the same code was working fine outside of the service.

In the end I eventually tracked it down to an error with the Distributed Transaction Coordinator service which NServiceBus uses to handle transactions. By using the DTCPing tool I was able to see that while my workstation could connect to the database server the server could not then connect back to my machine.

A bit more digging revealed that this was because the DNS entry for my computer’s host name was incorrect (I sometimes have to change it to access certain sets of servers and the DNS evidently can’t keep up).  Apparently this error or one very like it can also be caused by incorrect firewall settings.

As a temporary workaround I got it working by putting the correct IP in an entry in the server’s hosts file; since this is not a situation that will happen in a production environment I’m not that concerned. I believe another solution would be to run my service AsA_Client in NServiceBus and handle the transactions myself; I will probably end up doing this as it gives me a bit more control over how the transactions are implemented.

Loving NServiceBus though…