Code Keeps Timing Out

☆樱花仙子☆ 提交于 2019-12-01 23:08:33

have you tried

myCommand.Parameters.AddWithValue("@studynumber", studynumber);

instead of:

myCommand.Parameters.AddWithValue("@study", studynumber); 

EDIT If passing parameters is the problem, then it comes down to how much time the stored procedure takes to execute. Default timeout for SQL server is usually 120 secs. You can add "Connect Timeout" to increase timeout in your DB connection string and check out.

** Old Answer -- Ignore ** Without stack trace, and taking your word that the stored procedure is fine, I am guessing that it is timing out due to the connection failure. The code is unable to connect to your DB server and hence timing out.

setting arithabort off made the sp take 45 seconds as opposed to 1. setting it back on changed it back to 1. I updated the stored procedure to set it on, no change in the app. Changed it to off, no change. I then removed the update and then the app worked fine.

I believe what happened is that updating the stored procedure caused it to recompile, fixing the issue. I'm not 100% sure on this though.

One thing could be the ARITHABORT setting, set it to ON...NET defaults to OFF

run the proc in SSMS with ARITHABORT set to OFF and see if it runs slower now like from .NET

example

MyConnection.Execute "SET ARITHABORT ON"

Another thing is that your WHERE clause is not optimal, take a look at Do you use Column=@Param OR @Param IS NULL in your WHERE clause? Don't, it doesn't perform

does the proc run slow with parameters in SSMS? Can you show the execution plan?

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