WCF-SQL System.NullReferenceException: Object reference not set to an instance of an object

I recently got an unhelpful null reference error in a BizTalk WCF-SQL port, while attempting to connect to an Azure database.

System.NullReferenceException: Object reference not set to an instance of an object

For some reason I didn’t get an accompanying MSDTC error in my Event Viewer, but it turns out that ultimately that was the cause. I tried the same thing in another environment and did get the more helpful MSDTC error in addition to the null reference error, so it must depend on a logging setting that I haven’t uncovered yet.

So anyway, if you’re getting this error on a WCF-SQL port, just letting ya know that it might be worth checking if MSDTC is the cause. You could always go into the Send Port configuration, set UseAmbientTransaction to false, and try it again. If the problem only starts when you set UseAmbientTransaction to true, then the cause is something to do with MSDTC.

P.S. A bit of Googling suggests that generally you can’t use MSDTC between on-premise BizTalk and an Azure database, which is why I hit this problem. You could set up a new general Azure server instance and install SQL components and MSDTC components on that, and apparently that can work, but it sounds like hassle.

P.P.S. Don’t be tempted to leave the UseAmbientTransaction setting on false unless you understand the consequences of disabling MSDTC. Depending on use case, you will be risking either duplicate or lost messages in the event something goes wrong, which might be unacceptable. This is why the recommendation is normally to leave it on. Full explanation of MSDTC’s role is beyond the scope of this post, but I might revisit it later (or just use Google…).

 

Leave a comment

Your email address will not be published. Required fields are marked *