SQL Server Query Time Out Depending on Where Clause

Is it possible to set a timeout for a SQL query on Microsoft SQL Server?

As far as I know, apart from setting the command or connection timeouts in the client, there is no way to change timeouts on a query by query basis in the server.

You can indeed change the default 600 seconds using sp_configure, but these are server scoped.

How to set Timeout for a specific sql query?

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.



Related Topics



Leave a reply



Submit