A recent problem was a fast-executing stored procedure that timed out when it was called in the code.
Later, I saw two articles:
One of the articles is about
Today, when a colleague calls a stored procedure with code that times out, running in SQL Server Management Studio will soon have the result, and this is the last time I've had a situation, now record the solution as follows, and I'd like to give you a reminder.
The solution is to delete the extra space in the stored procedure.
Tongue, but this is the reality, the reality is cruel, the reality is ruthless, haha
It doesn't have to be the space that causes the timeout, try to see it.
The solution above is to remove the space in the stored procedure, but if so, the format of the stored procedure is not very friendly later maintenance is also cumbersome.
From the bitter, and then have the following solution: that is, in the database execution succeeds, so in the program to construct a SQL execution as follows SqlParameter param = new SqlParameter ("@project_id", project_id);
String selectcmd = String. Format ("Exec dbo.[ get*ro*ctco***] @project_id ", project_id);
DataSet ds = this. ExecuteQuery (CommandType.Text, Selectcmd, param); Executes the execution of the stored procedure as a SQL to the database.
OK, tangled you, hurry to try it ...
And the second explains the nature of the problem:
Immediately execute on Query Analyzer:
EXEC sp_recompile @objname=' stored procedure name '
Because the stored procedure is precompiled, the execution plan is generated at the time of the first execution and is executed at a later time, using the execution plan (unless the stored procedure or the display specifies recompilation) instead of generating the execution plan each time it executes.
The stored procedure should be recompiled when the object structure involved in the stored procedure is adjusted, or the related data has changed greatly, which may result in the original plan being unsuitable for the current situation (the execution plan expires).
In fact, if we add with Recompile in the stored procedure, it will achieve the same effect.
I'm also talking about code call stored procedure timed out, SQL Server Management Studio running fast problem