erwik
erwik

Reputation: 29

How to limit query execution time in SQL Server?

I am executing a query and stored procedure against MS SQL Server. Both php script and sql server reside on the same server. Sometimes it takes too much time to execute and the PHP script crashes. However SQL Server continues executing the queries in the background.

How can I force SQL Server to stop any queries which take more than X seconds to execute?

Upvotes: 2

Views: 15406

Answers (3)

Also you can increase the execution time of php via max_execution_time setting in your php.ini file or using the function set_time_limit in your php file

Upvotes: 0

Arkaitz
Arkaitz

Reputation: 39

You can use a server level setting, see Microsoft documentation.

  1. In Object Explorer, right-click a server and select Properties.
  2. Click the Connections node.
  3. Under Remote server connections, in the Remote query timeout box, type or select a value from 0 through 2,147,483,647 to set the maximum number seconds for SQL Server to wait before timing out.

Upvotes: 4

Endrju
Endrju

Reputation: 2456

There's a configuration parameter in PHP: mssql.timeout which defaults to 60 seconds and limits time to execute queries. After this time the MSSQL PHP driver will abort the query and report query timeout error.

But there's no such thing as "query timeout" in SQL Server itself :-)

Upvotes: -1

Related Questions