Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Slow after debugging website in Visual Studio

When I use Visual Studio 2015 to debug a website, using file -> open website... on my local development database, queries slows right down to the point where they take a minute or more instead of milliseconds. Similar queries run by hand using SQL Server Management Studio (SSMS) are slow while Visual Studio is running.

SQL Server instance is running on the same machine as Visual Studio environment.

Here is what I've tried:

  1. Stop Debug mode
  2. After stopping debug, kill IIS Express process
  3. Disabled IntelliTrace
  4. Close solution in Visual Studio

The issue still persists after the above, and the problem is resolved when Visual Studio is shut down or a different solution is opened.

I checked the sql connections from SSMS and the connections were cleared once IIS Express process. It appears to be some sort of integration that Visual Studio is instrumenting with SQL Server libraries that is at the root of this.

Anybody have an idea what this might be or how to troubleshoot this further?

like image 981
Timothy C. Quinn Avatar asked Aug 28 '26 00:08

Timothy C. Quinn


1 Answers

Another possible issue is how Visual Studio marshals exceptions. If your code has a bunch of exceptions that are caught in try catch blocks; each exception that is generated is intercepted by Visual Studio regardless of whether you handle them with a try catch. In recent versions of Visual Studio, I have measured about 40 milliseconds per exception. This may not seem like a lot but they add up. I have legacy .net applications that the original developer was prolific with try catch blocks to catch primitive type conversions and null handling.

The only way to get around this is to re-tool the code that generates the exceptions to not generate exceptions where ever possible. In my case, this was a massive undertaking but it paid off. I now have robust primitive type conversions and parsing that is fast when run in the debugger.

like image 99
Timothy C. Quinn Avatar answered Aug 30 '26 15:08

Timothy C. Quinn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!