I'm also talking about code call stored procedure timed out, SQL Server Management Studio running fast problem

Source: Internet
Author: User
Tags management studio sql server management sql server management studio

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.