Skip to content
Microsoft SQL Server

SQL Server Error 258

The wait operation timed out / execution timeout expired (not the engine message 258)

Severity 20 Connectivity
Applies to: Any SQL Server version through SQL Server client drivers (SqlClient, ODBC, OLE DB, JDBC report their own timeout wording)
Last technically reviewed 23 October 2026 on SQL Server 2025 (17.0.1145.4), ODBC Driver 18 for SQL Server
The full message
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out.
Other forms of this message
Connection (login) timeout in .NET (Microsoft documentation)
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgment. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was [Pre-Login] initialization=23; handshake=14979; System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out.
Query (command) timeout in .NET (Microsoft documentation)
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
sqlcmd query timeout (reproduced)
Timeout expired
sqlcmd with ODBC Driver 18, login timeout (reproduced)
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : TCP Provider: The wait operation timed out.
.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login timeout expired.
Not this error: engine message 258 in sys.messages
Cannot call methods on %ls.
Error number
258
Severity
20 (fatal: the connection ends; may indicate a serious problem)
State
0
Product
Microsoft SQL Server Database Engine
Versions
Any SQL Server version through SQL Server client drivers (SqlClient, ODBC, OLE DB, JDBC report their own timeout wording)
Category
Connectivity
Last reviewed
23 October 2026

What it means

Client error 258 (the wait operation timed out) means the client gave up waiting: either the connection did not complete within the connection timeout, or a query did not finish within the command timeout and the client cancelled it.

This page covers the client timeout family: Windows error 258 (WAIT_TIMEOUT, "The wait operation timed out") that SqlClient shows as the inner Win32Exception, and the "Timeout expired" or "Execution Timeout Expired" messages around it. It is not the SQL Server engine message 258 in sys.messages ("Cannot call methods on ..."), which is unrelated. SQL Server does not raise a timeout error to the client; the client stops waiting.

First decide which timeout fired. A connection timeout (15 seconds by default, per Microsoft) happens in SqlConnection.Open before any query runs: the server is unreachable or slow to answer the pre-login, as with 10060. A query timeout (30 seconds by default for SqlCommand.CommandTimeout) happens in ExecuteReader, ExecuteNonQuery or similar: the query ran too long and the client sent an Attention to cancel it, which SQL Server records as an attention event (error 3617). The stack trace tells you which one it was. sqlcmd and SQL Server Management Studio default to no query timeout, which is why a query can work there and time out in the application.

Common causes

  • A slow query: missing indexes, a poor plan, or far more rows than expected, so it runs longer than the command timeout (the most common cause, per Microsoft).
  • Blocking: the query waits on locks held by another session until the timeout expires.
  • The application uses different SET options from SSMS (for example ARITHABORT), so it gets a different, slower plan.
  • A connection timeout: the server name, port or firewall path is wrong, or the server is too busy to answer the pre-login in time.
  • The command timeout is set lower than the work genuinely needs, for example a 30 second default on a reporting query.

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

What is running now, and is it blocked?

SELECT r.session_id, r.status, r.command, r.wait_type, r.wait_time,
       r.blocking_session_id, r.total_elapsed_time / 1000 AS elapsed_s,
       t.text AS query_text
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.session_id <> @@SPID
ORDER BY r.total_elapsed_time DESC;
What to look for

Long elapsed_s values near the application timeout, or a non-zero blocking_session_id, identify the query and whether it is slow or blocked.

Which cached queries take longest per execution?

SELECT TOP (10)
       qs.execution_count,
       qs.max_elapsed_time / 1000 AS max_elapsed_ms,
       qs.total_elapsed_time / qs.execution_count / 1000 AS avg_elapsed_ms,
       SUBSTRING(t.text, 1, 200) AS query_start
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS t
ORDER BY qs.max_elapsed_time DESC;
What to look for

Queries whose max_elapsed_ms reaches the command timeout (30000 ms by default) are the candidates to tune.

Capture the timed-out statement with Extended Events

Microsoft recommends tracing the attention event together with sql_batch_completed and rpc_completed for the application, and matching them on session_id: a completed event whose duration is close to the timeout, followed by an attention, is the query that timed out.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Tune the query that times out

Read-only

Run the captured statement in SSMS with the actual execution plan, and fix the cause: a missing index, a non-sargable predicate, a parameter-sensitive plan or an unbounded result set. This is the fix Microsoft recommends over raising the timeout.

SET STATISTICS IO, TIME ON;
-- run the captured statement here and read the plan and logical reads

Resolve blocking

Read-only

If the request waits on a lock, find the head blocker with the first diagnostic and shorten its transaction (commit sooner, add indexes so updates touch fewer rows). See error 1222 for lock timeouts.

Set an explicit, realistic timeout for long work

Client or network side

For genuinely long operations (reports, maintenance), set CommandTimeout (ADO.NET), SQL_ATTR_QUERY_TIMEOUT (ODBC) or setQueryTimeout (JDBC) to a value that matches the job, instead of disabling the timeout everywhere.

// C#: give this one command 120 seconds
command.CommandTimeout = 120;

For connection timeouts, fix the network path

Client or network side

If the timeout is in SqlConnection.Open, check the server name, port and firewall as for 10060. Raising the connection timeout only helps on slow networks; Microsoft notes a healthy connection opens in milliseconds.

Examples

A query timeout: sqlcmd cancels a statement after 2 seconds

Reproduced with sqlcmd and ODBC Driver 18 on 2026-10-23. The -t 2 option sets a 2 second query timeout; the client cancels the 10 second WAITFOR and prints only "Timeout expired".

sqlcmd -S . -E -C -t 2 -Q "WAITFOR DELAY '00:00:10'"
Result
Timeout expired

A connection timeout: the server never answers

Reproduced on 2026-10-23 against 10.255.255.1, an address with no host. The 5 second login timeout (-l 5) expires while the driver waits, so it reports Windows error 258 as "The wait operation timed out".

sqlcmd -S tcp:10.255.255.1,1433 -E -C -l 5
Result
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : TCP Provider: The wait operation timed out.
.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to tcp:10.255.255.1,1433. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

How to prevent it

Treat a timeout as a performance alert, not a setting to raise: monitor the slowest queries, keep statistics and indexes healthy, and keep transactions short to avoid blocking. The performance tuning lesson and the tuning checklist cover the usual fixes.

Set timeouts deliberately per workload, log the full exception (including the stack trace that shows Open versus Execute), and keep an Extended Events session for attention events ready on busy servers.

Common questions

Is "The wait operation timed out" a SQL Server error?

No. It is the Windows wait timeout (error 258) reported by the client when it stopped waiting for a connection or a query. SQL Server only sees the cancellation (an attention). The engine message 258 in sys.messages is unrelated.

Why does the query run fine in SSMS but time out in my application?

SSMS has no query timeout by default and may use different SET options, which can give a different plan. Compare the options and the plan, then tune the query rather than only raising CommandTimeout.

Should I set CommandTimeout to 0?

Only for jobs that must run to completion, such as maintenance. For user-facing requests a timeout protects the application from waiting forever on blocked or runaway queries.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4), ODBC Driver 18 for SQL Server. Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.