How to Set Connection Timeout in SQL Server

Galaxy Glossary

How do I set and troubleshoot SQL Server connection timeout?

Connection timeout controls how long a client waits to establish a SQL Server session before aborting.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Description

Why change the SQL Server connection timeout?

Shortening or extending the timeout prevents apps from hanging during network hiccups or busy servers. Setting the value explicitly makes connection behavior predictable and easier to debug.

What is the default connection timeout value?

Most drivers, including ADO.NET and ODBC, default to 15 seconds. If the login handshake does not finish by then, an error is raised.

How do I set connection timeout in a connection string?

Add the keyword Connect Timeout=## (or Connection Timeout) where ## is the number of seconds. Zero means wait indefinitely, which is discouraged.

ADO.NET example

Server=tcp:prod-sql,1433;Database=ShopDB;User Id=app;Password=***;Connect Timeout=30;

sqlcmd example

sqlcmd -S prod-sql -d ShopDB -U app -P "***" -l 45

Can I modify timeout inside SQL Server?

Client timeout is external, but you can raise the server-side ceiling for remote queries so that distributed commands have more time to return.

Using sp_configure

EXEC sp_configure 'remote query timeout', 120; -- secondsRECONFIGURE;

How do I test if the new timeout works?

Throttle the network or pause the SQL Server service, initiate a connection, and confirm that the client errors out after the configured interval.

Best practices for choosing timeout values

Start at 30 seconds for web apps, 60–90 seconds for heavy ETL jobs. Monitor baseline connection times; set the limit slightly above the 95th percentile.

Common mistakes and how to avoid them

Leaving the value at zero causes hidden hangs. Setting it too low breaks initial logins on slow VPNs. Adjust, test, and document the chosen value.

Why How to Set Connection Timeout in SQL Server is important

How to Set Connection Timeout in SQL Server Example Usage


-- Raise remote query timeout to accommodate a long linked-server import
EXEC sp_configure 'remote query timeout', 180;  -- 3 minutes
RECONFIGURE;

-- After applying, import sales data without premature failure
INSERT INTO Orders (customer_id, order_date, total_amount)
SELECT customer_id, order_date, total_amount
FROM LinkedServer.ShopDB.dbo.Orders;

How to Set Connection Timeout in SQL Server Syntax


-- Connection string keyword
Connect Timeout = <seconds>

-- sqlcmd login timeout (seconds)
sqlcmd -S <server> -l <seconds>

-- PowerShell with Invoke-Sqlcmd
Invoke-Sqlcmd -ServerInstance "prod-sql" -Query "SELECT 1" -ConnectionTimeout 20

-- Server-side remote query timeout
after connecting:
EXEC sp_configure 'remote query timeout', <seconds>;
RECONFIGURE;

-- Example in ecommerce context
/* Client app connection string */
Server=tcp:analytics-sql;Database=ShopDB;User Id=reporter;Password=***;Connect Timeout=25;
/* Query once connected */
SELECT c.name, SUM(oi.quantity) AS items
FROM Customers AS c
JOIN Orders      AS o  ON o.customer_id = c.id
JOIN OrderItems  AS oi ON oi.order_id   = o.id
GROUP BY c.name;

Common Mistakes

Frequently Asked Questions (FAQs)

Does connection timeout affect running queries?

No. It only governs the login phase. Use COMMAND TIMEOUT (e.g., SqlCommand.CommandTimeout) for statements after the session is open.

Is Connect Timeout case-sensitive?

No. Connect Timeout and Connection Timeout are aliases and not case-sensitive.

Can I override timeout per query in SSMS?

Yes. In SSMS, Tools ➜ Options ➜ Query Execution ➜ SQL Server ➜ Execution time-out lets you control it for each window.

Want to learn about other SQL terms?