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
Use Variable with Top in Select Statement in SQL Server Without Making It Dynamic
How to Replace Specific Values in a Oracle Database Column
How to Find the Data Directory for a SQL Server Instance
What Does a (+) Sign Mean in an Oracle SQL Where Clause
How Do Null Values Affect Performance in a Database Search
Activerecord Find_Each Combined with Limit and Order
Sql: Two Select Statements in One Query
Script Entire Database SQL-Server
SQL Query to Show Gaps Between Multiple Date Ranges
SQL Query If Parameter Is Null Select All
Should I Use the Cascade Delete Rule
Is There Any Query for Cassandra as Same as SQL:Like Condition