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?
1 Answer
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.
2 Comments
Gopal Biswas
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
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.
sp_configure