Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query runs fast in Query Analyzer but slow in C# application [duplicate]

Possible Duplicate:
sql runs fast in ssms slow in asp.net

Using SQL Server 2005, there is a sql query on a few big tables and it times out in the program. However, when I run it in Query Analyzer, it finishes in about 30 seconds.

Why the difference?

like image 310
Fred Avatar asked Sep 15 '25 05:09

Fred


1 Answers

Usually these are SET setting differences, leading to different plans. In Management Studio the procedure is probably running with the same settings as were in place when it was created.

Take a look at sys.dm_exec_sessions for your ASP.Net application and for your SSMS session. I will hazard a guess that at least one of your SET settings is different. This can contribute to different plans (ultimately this gets attributed to parameter sniffing) and the app side usually ends up worse off.

See these other questions for a lot more details:

  • Stored procedure slow when called from web, fast from Management Studio
  • Procedure times out from ADO.NET but not in SSMS
  • Query times out when executed from web, but super-fast when executed from SSMS
  • ADO .NET vs. SQL Server Management Studio - ADO performs worse
  • sql runs fast in ssms slow in asp.net

And also read Erland Sommarskog's article, Slow in the Application, Fast in SSMS?

like image 198
Aaron Bertrand Avatar answered Sep 16 '25 22:09

Aaron Bertrand