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.
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.
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.
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
This should resolve your issue permanently.
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
Get-Service -Name MSDTC | Set-Service -StartupType Automatic
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.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly