Search code examples
sql-servertimeoutsettimeoutqsqlquery

How to set Timeout for a specific sql query?


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?


Solution

  • 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.