New SqlConnection() Hangs When IIS Express Has Been Idle

And an entire day is lost trying to debug it

[2 minute read]

About a week ago I was happily working away on an ASP.NET Web API project when I noticed something fishy happening. And by “fishy”, I mean incredibly, unbelievably, stupendously frustrating. When initially loaded, the application worked fine. Start the project, execute a command from Postman, get results. But after running for 8 or 10 minutes, results would suddenly stop coming back. It didn’t take long to figure out where it was failing, however why it was failing was another matter entirely. I still don’t understand what happened but, best as I can tell, my 32-bit IIS Express installation got borked somehow.

// Black Hole: What goes in, never escapes...
var connection = new SqlConnection(connectionString);

If the application had been running for more than approximately 8 or 10 minutes, the statement above would hang. Forever. No errors, nothing. As soon as it was executed, it was Game Over for that particular API request. It was such bizarre behavior that I created a video just in case my coworkers didn’t believe me. It only happened on one of my two development machines - plus none of my teammates had this problem - so I had to assume something was wrong with the machine I was using. But how in the hell could I fix it? Killing IIS Express from the system tray was of no use and I even found that not all instances of iisexpress.exe terminated as I’d expect. Restarting Visual Studio didn’t help, nor did rebooting my machine. I tried removing and reinstalling IIS Express. No dice. I was on the verge of reinstalling Visual Studio itself, when I found these settings for the first time:

Visual Studio IIS Express Settings

The option for Use the 64 bit version of IIS Express was not checked, so I went ahead and turned it on. I figured, can’t hurt!

Far from hurting anything, it actually fixed my problem, leading me to conclude that something, somehow got corrupted with my 32 bit version of IIS Express. Something that removing and reinstalling couldn’t rectify. Regardless, ever since I flipped the switch for 64 bit IIS Express, every attempt to new up a SqlConnection instance has returned and all instances of iisexpress.exe have terminated when I select Exit from the system tray icon. Thank god, because I was pulling my hair out. I’ll be very curious to see if I can go back to the 32 bit version after updating to Visual Studio 2015 Update 2.

Anyway, hopefully this post will save someone else the hours of frustration I endured.