Stored Procedure is taking time in execution

a 夏天 提交于 2019-12-10 21:44:15

问题


I am facing a very strange issue with SQL Server that I have a stored procedure and I am executing the procedure from C# code. The procedure will return a datatable / dataset.

My problem is that procedure is taking too much time in execution from C# code / ADO.NET code (around 2 minutes). But when I execute the same query from SQL Server, it's executing within a second.

Also I have tried by create new procedure with the same code (old procedure code) and when I am executing this new procedure from ADO.NET it's not taking much time. It's executing withing a second time in C#.

So I am not getting what is the issue with my old procedure.


回答1:


I am guessing that you have a bad execution plan when the procedure is called from code. When you run the stored procedure, you will have a different plan because the plan signature is different when running from SSMS by default.

see: http://www.sommarskog.se/query-plan-mysteries.html for some possible fixes and clarity.

If your procedure is parameter heavy, it may make sense to compile every time using option(recompile);



来源:https://stackoverflow.com/questions/42351290/stored-procedure-is-taking-time-in-execution

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