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

时间秒杀一切 提交于 2019-11-26 21:44:18

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/12483064/query-runs-fast-in-query-analyzer-but-slow-in-c-sharp-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!