"SqlException: MSDTC on server is unavailable" error in C# Code


One of my projects was working properly, and then I shifted it into another pc, now same code, throws the below error for some SQL queries.

SqlException: MSDTC on server is unavailable.

exception-SqlException-MSDTC-on-server-is-unavailable.png

It was working on the last PC without any issue, so I am not sure what's the error

I am using Entity framework in my C#, ASP.NET MVC project.

I am not posting any code, as Code is simple just updating data in the database in the background using HangfireIO.


Asked by:- Vinnu
1
: 5715 At:- 4/13/2018 12:18:56 PM
SQL C# ASP.NET







2 Answers
profileImage Answered by:- manish

As explained in your question description that code was working in older pc and now getting error " SqlException: MSDTC on server is unavailable"

Here is the possible solution for it.

  1. Click on Start–>Control Panel->Administrative Tools->Services
  2. Select the service “Distributed Transaction Coordinator”
  3. Right on the service and choose “Start” 

    distributed-services-start-sqlexception-msdtc-on-server-is-unavailable-error-in-c-code-min.png
  4. Also, make this service to run Automatically for solving this issue permanently

    auto-start-service-msdtc-min.png

When SQL Server and the Application Server are on different boxes

The above solution work well when SQL Server and the Application are on the same box. If they are deployed on different boxes then additionally you should follow these steps to correct the problem

  1. Click Start–>Control Panel –> Administrative Tools –> Component Services –> Computers
  2. Right click on My Computer and choose  Properties option
  3. Switch to MS DTC tab and check allow remote access

This should resolve your issue permanently.

3
At:- 4/14/2018 3:03:21 PM Updated at:- 4/14/2018 3:06:00 PM
Thanks 0
By : Vinnu - at :- 4/18/2018 1:20:37 PM


profileImage Answered by:- jon

You'll need to configure MSDTC, you can either open MMC and load the MSDTC plugin or use the following script to open inbound and outbound transactions.

REG QUERY "HKLM\Software\Microsoft\MSDTC\Security" /v NetworkDtcAccess
REG QUERY "HKLM\Software\Microsoft\MSDTC\Security" /v NetworkDtcAccessTransactions
REG QUERY "HKLM\Software\Microsoft\MSDTC\Security" /v NetworkDtcAccessInbound
REG QUERY "HKLM\Software\Microsoft\MSDTC\Security" /v NetworkDtcAccessOutbound
PAUSE

REG ADD "HKLM\Software\Microsoft\MSDTC\Security" /f /v NetworkDtcAccess /t REG_DWORD /d 1
REG ADD "HKLM\Software\Microsoft\MSDTC\Security" /f /v NetworkDtcAccessTransactions /t REG_DWORD /d 1
REG ADD "HKLM\Software\Microsoft\MSDTC\Security" /f /v NetworkDtcAccessInbound /t REG_DWORD /d 1
REG ADD "HKLM\Software\Microsoft\MSDTC\Security" /f /v NetworkDtcAccessOutbound /t REG_DWORD /d 1
PAUSE

net stop MSDTC
net start MSDTC
PAUSE

Using Powershell

Get-Service -Name MSDTC | Set-Service -StartupType Automatic

OR

Sometime this issue can also occur when Distributed Transaction Coordinator service from not running while MSDTC is running.

So to verify that, launch Component Services (dcomcnfg.exe), then expand Component Services > Computers > My Computer, from here click on 'COM+ Applications' to see if an error will pop-up with "COM+ unable to talk to Microsoft Distributed Transaction Coordinator".

To fix above issue, you need to disable the 'HP Hotkey Service" and "HotKeyServiceUWP" services. Once those were disable, MSDTC immediately started working.

0
At:- 6/23/2022 7:03:52 AM Updated at:- 6/23/2022 7:05:07 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use