Setting the SQL command timeout maximum value prevents queries from running indefinitely and consuming excessive server resources. This is essential for maintaining database performance and avoiding application hangs, especially in environments with long-running or poorly optimized queries. To adjust this setting, you need appropriate permissions to modify database or connection-level configurations, and you should understand the implications of setting timeout values too low (causing premature query termination) or too high (risking resource exhaustion).

What You'll Need

  • Access to the database server with sufficient privileges (e.g., sysadmin or equivalent role)
  • A database management tool such as SQL Server Management Studio (SSMS), Azure Data Studio, or command-line access via sqlcmd
  • Knowledge of whether you are configuring the timeout at the server, database, or connection level
  • Awareness of your application’s typical query execution times to set a reasonable threshold

Step-by-Step

  1. Connect to your SQL Server instance using SQL Server Management Studio (SSMS) with an account that has sysadmin privileges.
  2. In Object Explorer, right-click the server name and select Properties to open the Server Properties dialog box.
  3. Navigate to the Connections page in the left-hand menu.
  4. Under the Remote server connections section, locate the Remote query timeout setting.
  5. Enter the desired timeout value in seconds. The maximum allowable value is 2,147,483,647 seconds (approximately 68 years), which is the practical upper limit for a 32-bit signed integer.
  6. Click OK to save the changes. No server restart is required for this setting to take effect.
  7. To verify the change, run the following query in a new query window: SELECT @@MAX_PRECISION; — note this does not return timeout; instead, use EXEC sp_configure 'remote query timeout'; to see the configured value.
  8. If you need to set the timeout at the connection level (e.g., in an application), adjust the connection string. For example, in ADO.NET, add Connection Timeout=30; (value in seconds) to your connection string. The default is 15 seconds; setting it to 0 means wait indefinitely, which is not recommended.
  9. For Azure SQL Database, note that server-level timeout settings like remote query timeout are not configurable. Instead, adjust timeout values in your application connection string or use query hints like OPTION (QUERY_TIMEOUT 60) for individual queries.
  10. After applying changes, monitor query performance using SQL Server Profiler, Extended Events, or Dynamic Management Views (DMVs) like sys.dm_exec_requests to identify any queries that are now timing out unexpectedly.

Common Mistakes

  • Setting the timeout too low (e.g., below 30 seconds) for reporting or data warehouse queries, causing legitimate long-running operations to fail.
  • Confusing command timeout with query execution timeout or deadlock timeout — these are separate settings with different scopes.
  • Assuming that changing the server-level remote query timeout affects all client connections uniformly; some drivers or middleware may override it.
  • Setting the timeout to 0 (infinite wait) in production applications, which can lead to connection pool exhaustion during blocking queries.
  • Failing to test timeout changes in a staging environment before applying them to production, risking unexpected query failures.

Tips

  • Base your timeout value on historical query performance data — examine average and 95th percentile execution times for similar workloads.
  • Use application-level timeout settings when possible, as they provide more granular control than server-wide configurations.
  • Consider using query optimization (indexing, statistics updates, query rewriting) before increasing timeouts, as timeouts often mask underlying performance issues.
  • In .NET applications, the SqlCommand.CommandTimeout property can override the connection timeout; check both if timeouts are not behaving as expected.
  • Document any timeout changes in your change management system, including the rationale and expected impact.

Troubleshooting

If queries are still timing out after adjusting the setting:

  1. Confirm the change was applied correctly by re-running EXEC sp_configure 'remote query timeout'; and verifying the run_value matches your setting.
  2. Check whether the timeout is occurring at the network level (e.g., firewall, load balancer) or within the application driver — use network tracing or client-side logs to isolate.
  3. Look for blocking queries using SELECT * FROM sys.dm_exec_requests WHERE blocking_session_id <> 0; — a blocked query may appear to timeout due to waiting, not execution time.
  4. Review SQL Server error logs for messages about timeouts or canceled queries.
  5. If using connection pooling, reset or recycle the pool after changing timeout settings, as pooled connections may retain old settings.
  6. Temporarily increase the timeout significantly (e.g., to 300 seconds) to test whether the issue is timeout-related or due to another problem like deadlocks or resource contention.

Frequently Asked Questions

What is the maximum value for SQL command timeout?

The maximum value for the remote query timeout setting in SQL Server is 2,147,483,647 seconds, which is the largest value a 32-bit signed integer can hold.

Does changing the timeout require a server restart?

No, changes to the remote query timeout setting take effect immediately without requiring a server restart.

Can I set different timeouts for different databases on the same server?

No, the remote query timeout is a server-level setting and applies uniformly to all remote connections. For database-specific control, use application-level connection strings or query hints.

Is it safe to set the timeout to 0?

Setting the timeout to 0 means wait indefinitely, which is not recommended in production as it can lead to unresponsive applications and exhausted connection pools during long blocks.

Why do my queries still timeout even after increasing the setting?

This may be due to application-level overrides, network timeouts, blocking queries, or the query actually exceeding the new limit — verify the source of the timeout using DMVs and client logs.

How does command timeout differ from query timeout in Azure SQL Database?

In Azure SQL Database, server-level timeout configurations are not available; you must manage timeouts through connection strings, application code, or query hints like OPTION (QUERY_TIMEOUT n).