June 23, 2015

ERROR: MSDTC on server 'SomeServerName' is unavailable.

This exception is rise when you use 'TransactionScope' in your LINQ to SQL or LINQ to Entity logic where updating the database with multiple tables at once. Exception is belongs to 'System.Data.SqlClient.SqlException'. Exception is raised because of 'Distributed Transaction Coordinator' which not enabled or running on your server/machine.


We have three different types of methods available in order to fix the exception:

1. Check the firewall settings:

In Run, type firewall.cpl.
Click Exceptions Tab.
Click Add Program.
Browse for Msdtc.exe (normally found under C:\Windows\System32).
Click Add Port.
In the Add A Port window, give a name in the Name field.
Give 135 in the Port Number Field.
Select TCP.
Click OK.

2. Start via Services

Method A:
Find the service called 'Distributed Transaction Coordinator'.
RIGHT CLICK (on it and select) > Start.

Method B:

Type services.msc in the run command box
Select “Services” manager; Hit Enter
Select the service “Distributed Transaction Coordinator
Right on the service and choose “Start

3. Use this for windows Server 2008 r2

Click Start, click Run, type dcomcnfg and then click OK to open Component Services.
In the console tree, click to expand Component Services, click to expand Computers, click to expand My Computer, click to expand Distributed Transaction Coordinator and then click Local DTC.
Right click Local DTC and click Properties to display the Local DTC Properties dialog box.
Click the Security tab.
Check mark "Network DTC Access" checkbox.
Finally check mark "Allow Inbound" and "Allow Outbound" checkboxes.
Click Apply, OK.


We can check that either the 'Distributed Transaction Coordinator' is enabled or not. In LINQ to Entity, we use 'TransactionScope.Complete();' line at the end of transaction. Run the application using breakpoint and you can check that either this line is parsed successfully or raise error/exception. 

If it is parsed then it means 'Distributed Transaction Coordinator' is enabled successfully and if it is not try the other method mentioned above in the post.

Let me know if you face any exception after implementing the suggested methods.