3

I want to set Timeout value for a specific sql query which will execute inside a stored procedure. Is it possible to set the timeout value for a particular query?

5
  • 1
    why you are trying to use in sql instead of using in .net or java Commented Aug 18, 2016 at 11:22
  • SQL Server won't stop running your query, you should set the timeout in the client from where you perform the connection. If it's SSMS you can use sp_configure Commented Aug 18, 2016 at 11:25
  • I'm using .Net in front end and there is an option from SqlCommand to set the timeout like command.CommandTimeout = 10000. Are you referring this to me? @Mani Commented Aug 18, 2016 at 11:56
  • yes you are correct @gopal Commented Aug 18, 2016 at 12:03
  • Thanks for your suggestion. Actually I'm looking for the same option for a stored procedure in SQL Server. @ Mani Commented Aug 18, 2016 at 12:08

1 Answer 1

1

It is the client API rather than SQL Server that enforces query timeouts (RPC or batch). Consequently, you can't set a client command timeout at a more granular level when a stored procedure contains multiple statements. You'll need to split the proc such that the desired query is executed separately by the client, and specify a different timeout for that command.

The specifics of how to set the timeout vary depending on the client API. In the case of .NET, it is the SqlCommand.CommandTimeout property.

Sign up to request clarification or add additional context in comments.

2 Comments

Suppose the proc contains only one query then what is the way to specify timeout for that proc? Is it from front end like .Net/ java... SqlCommand? @Dan Guzman
The CommandTimeout property of .Net SqlCommand will control the timeout. From Java, I think it depends on the driver (e.g. supports setQueryTimeout() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.