Alexander Beletsky's development blog

My profession is engineering

MSDTC on server is not available exception

During implementation of Linq to SQL of Entities application you can see such exception:

System.Data.SqlClient.SqlException : MSDTC on server ‘SRV\5118CF33-D353-46’ is unavailable.

Generally it means that there are several transactions is being created in application and they have to be managed by a special service, called “Distributed Transactions Coordinator” that is by default is not started. So, the quickest solution is just to start the service manually. Go to Start -> Control Panel -> Administrative Tools -> Services and start “Distributed Transactions Coordinator”. If it is required by your configuration you can set it as “Automatic” startup type, to run at as your server up.

But please be sure what you are doing, because this exception could also show some issues in application. As soon as it is appeared after some code changes, you have to clearly understand that involvement of Distributed Coordinator is expected behaviour.

What happened to me with my Linq to SQL application is following: there are two classes that create instance of DataModel class, first one is DbSetup that responsible for some preparation of data for tests, second is Repository object. DbSetup was also opening a TransactionScope object, to rollback all data that is being created during tests. This what created a problem - as soon as TransactionScope opened in scope of DataModel within DbSetup class, DataModel created in Repository was treated by runtime as a part of another transaction. That’s why runtime starting to request “Distributed Transactions Coordinator” to manage transactions. So, in unit test code I changed the constructor of Repository to accept DataModel created in DbSetup as constructor argument, so only one “transacted” DataModel object used in application. That solved my problem, without starting up coordinator.