Published: 2026-11-05

Why the first SQL Server query after a break is slow (measured on 85 machines)

You come back from a meeting, run the same query that took a tenth of a second before, and it takes half a second or more. The usual reason is on the client side: the connection your tool used was closed while you were away, so the first query has to wait for a new one — a TCP connection, the pre-login exchange, a TLS handshake and the login, about five network round trips before SQL Server sees your query. In Jam SQL Studio’s anonymous usage telemetry, the median time to the first rows of a SQL Server query was 128 ms when the previous query on that machine was less than a minute earlier and 471 ms after a pause of 1 to 30 minutes; machine by machine, the median penalty was +270 ms, and 81 of 85 machines were slower after a pause. A wait of a minute or more has a different cause, usually an Azure SQL serverless database resuming from auto-pause. AUTO_CLOSE, a cold cache after a restart and the Azure SQL gateway’s 30-minute idle cutoff cause the rest. Below: what each one costs, the T-SQL to tell them apart, and what changed when Jam SQL Studio 1.5.8 started opening connections ahead of time (it roughly halved the penalty, it did not remove it).

Five causes of a slow first query, by how long they add

CauseExtra time on the first queryWhere it happensSign
The client closed its idle connection, so the query waits for a new loginAbout five round trips plus the server’s login work: tens of milliseconds on a LAN, several hundred over a VPN or to a cloud region (our median: +270 ms)Any client with a connection pool, any SQL Serverconnect_time of your session is a moment old
The database was paused and resumes“Generally about one minute”, sometimes about a secondAzure SQL Database serverless (General Purpose; Hyperscale in preview)Error 40613 on the first attempt
AUTO_CLOSE shut the database downThe time to open the database, plus recompiling every planSQL Server (not Azure SQL Database)sys.databases.is_auto_close_on = 1
Data pages and plans are no longer in memoryDepends on how much the query reads from disk; a second run is fastAfter a restart or memory pressure; serverless databases also shrink their cache when idlePhysical reads and compile time in SET STATISTICS IO / TIME
Something on the network closed the connection your tool heldAn error on the first run, or a reconnect if the client retriesAzure SQL with the Proxy policy (30 minutes without a query); firewalls and NAT devicesThe first run after a long pause fails, the second works

The first row is by far the most common for anyone who works against a server that is not on their own machine, and it is the one people rarely suspect, because nothing fails: the query is just slower.

What a new SQL Server connection costs

Opening a connection to SQL Server is a short conversation, and each step waits for the server’s answer before the next one starts:

  1. TCP connection to port 1433 (or the instance’s port): one round trip.
  2. Pre-login: the client and server exchange versions and agree on encryption. One round trip.
  3. TLS handshake, carried inside the TDS protocol: two round trips with TLS 1.2. With Encrypt=Strict (TDS 8.0, SQL Server 2022 and later) the TLS handshake comes first, before pre-login.
  4. Login (the LOGIN7 message): the server checks the credentials, sets up the session and the database context, and answers. One round trip plus the server’s own work.

That is about five round trips before the first query is sent. At 50 ms between you and the server, a quarter of a second goes before SQL Server has seen your SELECT. Two Azure-specific steps can add to it:

  • The Azure SQL gateway. Every Azure SQL Database connection starts at a regional gateway on port 1433. With the Redirect policy the client is then sent to the node that hosts the database and talks to it directly; with Proxy, every packet keeps going through the gateway, which Microsoft says “increases latency and reduces throughput”. The Default policy is Redirect for clients inside Azure and Proxy for clients outside it, such as your laptop (connectivity architecture).
  • Microsoft Entra ID sign-in. The driver needs an access token, which costs a request to Entra ID when it has no valid one cached.

A connection pool exists to pay this once and reuse the connection. But every pool closes connections that sit unused, and when it has closed the last one, the next query pays the whole conversation again. How long a pool waits depends on the client:

  • Microsoft.Data.SqlClient (.NET): with the defaults, “periodic cleanup normally removes unused connections above Min Pool Size after about four to eight minutes”, and version 7.1 adds a Connection Idle Timeout setting (300 seconds by default, enforced when you opt in) (SqlClient connection pooling). Min Pool Size is 0 by default.
  • The mssql package for Node.js: pool.min 0 and pool.idleTimeoutMillis 30,000 by default, so an unused connection is closed after 30 seconds.
  • A GUI tool that holds one connection per editor, as an SSMS query window does, keeps it open while you are away. That avoids the login, but the connection can still be closed by the network (see step 5 below), and an open session keeps a serverless database from pausing.

What we measured: the pause penalty on 85 machines

Jam SQL Studio’s query runs report, in its anonymous usage telemetry (on by default, off in Settings → Privacy, never with SQL text, server names or data), how long a run took to deliver its first batch of rows to the app. In the data we pulled on November 1, 2026 we put each run next to the time since the same machine’s previous run, and compared every machine with itself: only machines with at least 10 runs after a short gap and 10 after a pause, over 30 days, on versions before 1.5.8.

EngineMachinesMedian extra time after a 1–30 min pauseMachines slower after a pause
SQL Server85+270 ms81
PostgreSQL13+101 ms11
MySQL60+5 ms—
SQLite (no network)—0 ms—
  • SQL Server: the median time to the first rows was 128 ms after a gap under a minute and 471 ms after a gap of 1 to 30 minutes. (The per-machine penalty, +270 ms, is the median of each machine’s own difference, which is why it is not 471 minus 128.)
  • The slow tail grows too: 5.0% of SQL Server runs after a short gap took 2 seconds or more to their first rows, against 11.7–14.1% after a pause, depending on its length.
  • It is common: in the 14 days to November 1, 39% of SQL Server runs (4,217 of 10,734) came after a gap of a minute or more, and almost half of those after 1 to 5 minutes. People read results, think, edit and run again.
  • The controls agree. MySQL showed almost no penalty because most of those machines query a server on the same computer, and Jam SQL Studio keeps one connection open to a local server. SQLite has no network connection at all and showed none.

Why would Jam SQL Studio close connections at all? For a remote server it holds no standing idle connection, on purpose: an open session stops an Azure SQL serverless database from auto-pausing (Microsoft calls open sessions “the most common reason for a serverless database to not auto-pause”), some services bill or limit connections, and a bastion host has a session budget. Microsoft gives the same advice for applications: a positive Min Pool Size “usually works against scale-to-zero, serverless auto-pause, and burstable cloud designs.” So a connection released after a query stays in the pool for 30 seconds and is then closed, and before 1.5.8 Jam opened a new one early only when the editor took focus, when you typed, or when a Table Explorer tab opened. Re-running with the Execute button and running Select top 1000 rows from the Object Explorer did neither. The Object Explorer case showed it: those runs took a median 438 ms after a pause against 127 ms without one.

We reproduced it in the lab with a proxy that adds 50 ms to every round trip. A SQL Server query whose pool had been emptied took 536 ms to its first rows. Jam SQL Studio asks SQL Server for the result’s column types on a second connection while the query runs, so after a pause it waited for two logins; with two connections opened ahead of time, the same query took 210 ms.

Before and after Jam SQL Studio 1.5.8

Jam SQL Studio 1.5.8 (released November 1, 2026) opens the connection on more signs that you are about to run something: the pointer reaching the Execute or plan button (or keyboard focus landing on it), the cursor or selection moving in the editor, a query or Table Explorer tab becoming the active tab, and the Object Explorer’s context menu opening on a table, view or partition, plus the click on Select top 1000 rows itself. For a remote SQL Server it opens two connections, for the query and for the column-type lookup. A run that starts while one of these connections is still being opened waits for it instead of opening another. Connections still close 30 seconds after their last use, so nothing stays open while you are away.

Three days after the release, the first-rows times on SQL Server looked like this (1.5.8 had been used in 174 sessions by then, so treat the 1.5.8 numbers as early):

SQL Server: median time to first rows after a pause, Jam SQL Studio 1.5.7 vs 1.5.8
1–5 min
467 ms
296 ms
5–30 min
522 ms
304 ms
Over 30 min
524 ms
295 ms

Bars start at 0 ms; the scale ends at 600 ms. Same data as the table below.

Pause before the runMedian first rows, 1.5.7Median first rows, 1.5.8Runs of 2 s or more, 1.5.7Runs of 2 s or more, 1.5.8
1–5 minutes467 ms296 ms14.2%13.6%
5–30 minutes522 ms304 ms16.1%6.6%
Over 30 minutes524 ms295 ms15.3%8.4%

The median after a pause fell by about 40%, and slow runs after pauses of 5 minutes or more fell by half. That is not the same as removing the penalty:

  • In sessions that had runs both with and without a pause, a run after a pause was still a median +122 ms slower (14 sessions on 1.5.8), down from +159 ms (40 sessions on 1.5.7). Our target was under 80 ms.
  • After a 1–5 minute pause, the share of runs that took 2 seconds or more did not move (14.2% and 13.6%).
  • Not all of what is left is the connection. Runs after a pause of a minute or more that got an already-open connection still had a median of 297 ms, against 113 ms for runs in a busy stretch. The column-type lookup and the kind of query people run after a break both play a part, and the telemetry does not yet separate them.

One case the same data turned up, which the next release fixes. In 1.5.8 and earlier, a SQL Server run that calls a stored procedure or runs dynamic SQL (EXEC) or holds several GO batches runs on a connection opened for that run alone and closed after it, because Jam SQL Studio cannot be sure that resetting a connection undoes everything a procedure changed in the session. Such a run pays a login however recently you ran something. On 1.5.8, 57 of 477 SQL Server runs (12%) that started less than 30 seconds after the previous run still opened a new connection, and one session did so on all 14 of its runs, with first rows after 190–330 ms instead of about 90 ms; we believe most of them are runs of this kind, though the telemetry does not yet record which path a run took. The next release runs these on a connection the pool already has open, when it has one, then closes that connection after a procedure call (a GO script that contains one included) and resets it after any other GO script, so they no longer pay a login of their own.

Which one do you have? Five checks

1. Did this run open a new connection? Run your query after the pause, then this in the same batch (a batch runs on one connection):

SELECT c.connect_time,
       DATEDIFF(millisecond, c.connect_time, SYSDATETIME()) AS ms_since_connect,
       c.encrypt_option,
       c.auth_scheme
FROM sys.dm_exec_connections AS c
WHERE c.session_id = @@SPID;

If ms_since_connect is under a second after a pause of minutes, your tool opened a new connection for this run, and the extra time is the login. The view needs VIEW SERVER STATE on SQL Server (VIEW SERVER PERFORMANCE STATE from SQL Server 2022) and, on most Azure SQL Database service objectives, VIEW DATABASE STATE (sys.dm_exec_connections). Most drivers also count physical connections: SqlClient’s diagnostic counters separate “hard connects” (new logins) from “soft connects” (pool checkouts).

2. Was an Azure SQL serverless database paused? If the first attempt fails with error 40613 (the database is not currently available) and a retry a minute later works, the database was resuming. Serverless databases have service objectives with _S_ in the name, such as GP_S_Gen5_2:

SELECT DATABASEPROPERTYEX(DB_NAME(), 'ServiceObjective') AS service_objective;

In the General Purpose tier the auto-pause delay is 60 minutes by default and at least 15; a database pauses when it has had no sessions and no user CPU for that long. Resuming is “generally about one minute”, and Microsoft’s fix is retry logic, or turning auto-pause off with a delay of -1 (auto-pause and auto-resume). The Azure activity log records each Resume Databases operation and what triggered it.

3. Is AUTO_CLOSE on?

SELECT name FROM sys.databases WHERE is_auto_close_on = 1;

ALTER DATABASE [YourDatabase] SET AUTO_CLOSE OFF;

With AUTO_CLOSE ON the database “is shut down cleanly and its resources are freed after the last user exits”, and the next user waits while it is opened, which “might take some time and can result in application timeouts.” Each shutdown also clears the plan cache for the whole instance, and the error log shows a cachestore flush message for it (ALTER DATABASE SET options). The option does not exist on Azure SQL Database.

4. Is the cache cold? Run the query twice with statistics on and compare:

SET STATISTICS IO ON;
SET STATISTICS TIME ON;
-- your query here

If the first run shows physical reads or read-ahead reads and a large SQL Server parse and compile time, and the second shows only logical reads, the data or the plan had left memory. SELECT sqlserver_start_time FROM sys.dm_os_sys_info; tells you whether the instance restarted recently. An Azure SQL serverless database also “reclaims memory from the SQL cache when CPU or active cache utilization is low” (serverless memory management), so it can be cold without having paused. The penalty from a cold cache is in the query’s own execution time, which STATISTICS TIME shows; the login cost from check 1 is not.

5. Was the connection closed underneath your tool? If the first run after a long pause fails with a connection error and the second works, something closed the idle connection. For Azure SQL Database, Microsoft documents that with the Proxy policy the gateway terminates a connection that has “not had an active query in 30 minutes”, even while TCP keepalives are flowing; the fix it suggests is the Redirect policy (connections dropped). az sql server conn-policy show --resource-group <group> --server <server> shows the server’s policy. Firewalls, NAT gateways and VPNs drop idle TCP connections on their own schedules.

If the query is slow on every run, not only on the first one after a pause, it may be waiting for a lock that another session holds. Find the blocking session and kill it walks through that case.

What to do about it

  • In your own application, keep pooling on and treat the first query after a quiet period as one that may pay a login. Raise Min Pool Size only when you have measured that the login matters and the database is not serverless. Add retry logic for 40613 if it is.
  • For a serverless development database, decide which you would rather have: the pause (and its minute on the first connection) or the compute bill. Raising the auto-pause delay to cover your working day removes most resumes.
  • Turn AUTO_CLOSE off on any database people query interactively.
  • Use the Redirect connection policy on Azure SQL Database when your network allows outbound ports 11000–11999 to the region’s Azure SQL addresses. Microsoft recommends it for latency and throughput, and the gateway’s 30-minute idle cutoff does not apply to it.
  • In a GUI client, a tool that keeps the editor’s connection open avoids the login and holds a session on the server while you are away. A tool that opens the connection when you start working pays the login before you press Run, most of the time. Jam SQL Studio does the second for remote servers and keeps one connection open for a server on your own machine.

Quick Answers

Q: Why is the first SQL Server query after a break slow?

A: Usually because the connection your tool used was closed while you were away, so the first query waits for a new one: a TCP connection, the pre-login exchange, a TLS handshake and the login, about five network round trips. In Jam SQL Studio's anonymous telemetry the median machine waited 270 ms longer for the first rows after a pause of 1 to 30 minutes than after a pause of less than a minute. A wait of a minute or more points at Azure SQL serverless auto-pause instead.

Q: Why does Azure SQL Database take about a minute to answer after being idle?

A: A serverless database in the General Purpose tier pauses when it has had no sessions for its auto-pause delay (60 minutes by default, at least 15). The first login then fails with error 40613 while the database resumes, which Microsoft says generally takes about a minute. Retry the connection, raise the delay, or turn auto-pause off by setting the delay to -1.

Q: Does AUTO_CLOSE make the first query slow?

A: Yes. With AUTO_CLOSE ON, SQL Server shuts the database down after the last user disconnects and has to open it again for the next one, which Microsoft says might take some time and can cause application timeouts. Each such shutdown also clears the instance's plan cache. Check sys.databases.is_auto_close_on and run ALTER DATABASE ... SET AUTO_CLOSE OFF. Azure SQL Database does not have the option.

Q: How do I check whether my query opened a new connection?

A: Run SELECT connect_time FROM sys.dm_exec_connections WHERE session_id = @@SPID in the same batch as your query. If connect_time is less than a second old after a pause, the tool opened a new connection for that run. The view needs VIEW SERVER STATE on SQL Server (VIEW SERVER PERFORMANCE STATE from SQL Server 2022) and VIEW DATABASE STATE on most Azure SQL Database service objectives.

Q: Should I keep a connection open to avoid the delay?

A: For a server on your own machine or a provisioned server, one open connection removes the wait. For an Azure SQL serverless database it stops the database from pausing, because open sessions prevent auto-pause, and Microsoft's SqlClient documentation says a positive Min Pool Size usually works against serverless auto-pause. Opening the connection just before you need it avoids both problems.

Q: Why does Azure SQL close my connection after 30 minutes?

A: With the Proxy connection policy, the default for clients outside Azure, the Azure SQL gateway closes a connection that has run no query for 30 minutes, even when TCP keepalives are flowing. Microsoft recommends the Redirect policy instead, which needs outbound ports 11000 to 11999 open to the region's Azure SQL addresses.

How we measured

The field numbers come from Jam SQL Studio’s anonymous usage telemetry, which users can turn off in Settings → Privacy. Each successful query run reports the engine and the time from the start of the run until its first batch of rows reached the app; it carries no SQL text, server name or data. The gap is the time since the same machine’s previous run. The per-machine comparison covers the 30 days to November 1, 2026, on versions before 1.5.8, and includes only machines with at least 10 runs after a gap under one minute and 10 after a gap of 1 to 30 minutes. The 1.5.7 and 1.5.8 comparison was pulled on November 4, 2026, three days after 1.5.8 was released. The numbers describe Jam SQL Studio users’ servers and networks, which we cannot see; they show how large the effect is in practice, not what it will be on your connection. The lab figures come from Jam SQL Studio’s own test suite, which puts a proxy adding 50 ms per round trip between the app and a SQL Server container. The Microsoft behaviour is quoted from the pages linked where it appears.

Summary

When the first SQL Server query after a break takes a few hundred milliseconds longer, the connection was almost always closed while you were away and the query waited for a new login: TCP, pre-login, TLS and the login itself, about five round trips. When it takes about a minute and fails first with 40613, an Azure SQL serverless database was resuming. AUTO_CLOSE, a cold cache and connections dropped by the Azure gateway or the network explain the rest, and the checks above tell them apart. Jam SQL Studio 1.5.8 now opens the connection when you show you are about to run something, which cut the median wait after a pause by about 40%; the remaining penalty is smaller but still there.

Last verified against learn.microsoft.com (Azure SQL serverless, connectivity architecture, ALTER DATABASE SET options, sys.dm_exec_connections, SqlClient connection pooling, JDBC on Azure SQL) and the mssql package README on 2026-11-05.

Related