Skip to content

Commit 325e2d2

Browse files
authored
Merge pull request #10303 from haywoodsloan/8521-sql-agent-job-failed
AB#8521: Error 258 SQL Agent Job Failed
2 parents 9a99862 + e7ce2b5 commit 325e2d2

2 files changed

Lines changed: 247 additions & 0 deletions

File tree

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
---
2+
title: Troubleshoot SQL Server Agent Job Failures with Error 258
3+
description: Troubleshoot SQL Server Agent job failures (error 258). Learn how to resolve timeout issues, fix registry problems, and ensure stable job execution.
4+
ms.date: 12/04/2025
5+
ms.custom: sap:SQL Agent (Jobs, Alerts, Operators)\Job failures, job scheduling and monitoring
6+
ms.reviewer: prmadhes, v-shaywood
7+
---
8+
9+
# SQL Server Agent job fails and returns error 258
10+
11+
This article provides troubleshooting guidance for an issue that causes Microsoft SQL Server Agent jobs to fail and generates error code 258.
12+
13+
## Symptoms
14+
15+
The [SQL Server Agent service](/ssms/agent/sql-server-agent#sql-server-agent-components) runs, but scheduled SQL Server Agent jobs don't run. The SQL Server and Agent logs show network and authentication timeouts in addition to failed sign-ins.
16+
17+
The following example shows the error message that's added to the logs:
18+
19+
```output
20+
SQLServer Error: 258, TCP Provider: Timeout error [258]
21+
ODBC Error: 0, Login timeout expired [SQLSTATE HYT00]
22+
SQLServer Error: 258, Unable to complete login process due to delay in prelogin response [SQLSTATE 08001]
23+
Logon to server '<ServerName>' failed (ConnLogJobHistory)
24+
```
25+
26+
## Cause
27+
28+
This issue can be caused by any of the following underlying problems:
29+
30+
- Blocking on [msdb](/sql/relational-databases/databases/msdb-database) system tables that SQL Agent uses. This blocking prevents job metadata read and write operations.
31+
- Example system tables include `dbo.sysjobs`, `dbo.sysjobschedulers`, and `dbo.jobsteps`.
32+
- Non response (hangs) in important SQL Server Agent threads or other process-level problems.
33+
- Worker thread exhaustion in SQL Server (no workers available). This exhaustion prevents the Agent from connecting or processing schedules.
34+
35+
## Solution
36+
37+
1. Verify that the SQL Server Agent service is running. Use one of the following PowerShell commands:
38+
39+
- For default SQL instances:
40+
41+
```powershell
42+
Get-Service -Name "SQLSERVERAGENT"
43+
```
44+
45+
- For named SQL instances:
46+
47+
```powershell
48+
Get-Service -Name "SQLSERVERAGENT$<InstanceName>"
49+
```
50+
51+
1. If the SQL Server Agent service isn't running, start it by using one of the following commands:
52+
53+
- For default SQL instances:
54+
55+
```powershell
56+
Start-Service -Name "SQLSERVERAGENT"
57+
```
58+
59+
- For named SQL instances:
60+
61+
```powershell
62+
Start-Service -Name "SQLSERVERAGENT$<InstanceName>"
63+
```
64+
65+
1. If jobs continue to fail after you start the SQL Server Agent service, go to the next step. If jobs are finishing successfully, the issue is resolved and no further action is required.
66+
1. Check the jobs and schedules in `msdb`. Start [SQL Server Management Studio (SSMS)](/ssms/install/install), and run the following query:
67+
68+
```tsql
69+
USE msdb;
70+
GO
71+
-- List enabled jobs
72+
SELECT name, enabled, description
73+
FROM msdb.dbo.sysjobs
74+
WHERE enabled = 1;
75+
GO
76+
-- List schedules and next run information
77+
SELECT
78+
s.name AS ScheduleName,
79+
j.name AS JobName,
80+
s.enabled AS ScheduleEnabled,
81+
s.active_start_date,
82+
s.active_end_time
83+
FROM msdb.dbo.sysjobs j
84+
JOIN msdb.dbo.sysjobschedules js ON j.job_id = js.job_id
85+
JOIN msdb.dbo.sysschedules s ON js.schedule_id = s.schedule_id
86+
WHERE j.enabled = 1;
87+
GO
88+
```
89+
90+
Analyze the query output for any jobs that are enabled but failed. Investigate the job history and job-step outputs for any problematic jobs to identify and fix underlying problems.
91+
92+
1. Detect blocking sessions on `msdb` Agent system tables by running the following query in SSMS:
93+
94+
```tsql
95+
USE msdb;
96+
GO
97+
SELECT
98+
session_id,
99+
blocking_session_id,
100+
wait_type,
101+
wait_duration_ms,
102+
resource_description
103+
FROM sys.dm_os_waiting_tasks
104+
WHERE resource_description LIKE '%sysjobs%'
105+
OR resource_description LIKE '%sysjobschedulers%'
106+
OR resource_description LIKE '%jobsteps%';
107+
GO
108+
```
109+
110+
- To identify the query that's associated with a blocking session, run the following query in SSMS:
111+
112+
```tsql
113+
SELECT
114+
wt.session_id,
115+
wt.blocking_session_id,
116+
wt.wait_type,
117+
wt.wait_duration_ms,
118+
wt.resource_description,
119+
er.status,
120+
er.command,
121+
er.cpu_time,
122+
er.total_elapsed_time,
123+
txt.text AS sql_text
124+
FROM sys.dm_os_waiting_tasks wt
125+
LEFT JOIN sys.dm_exec_requests er
126+
ON wt.session_id = er.session_id
127+
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) AS txt
128+
WHERE wt.resource_description LIKE '%sysjobs%'
129+
OR wt.resource_description LIKE '%sysjobschedulers%'
130+
OR wt.resource_description LIKE '%jobsteps%';
131+
```
132+
133+
1. Resolve or terminate any blocking sessions that you identified in the previous step. To terminate a session, run the following query in SSMS:
134+
135+
```tsql
136+
Kill <Blocking_Session_ID>
137+
```
138+
139+
After all blocking sessions are resolved or terminated, go to the next step.
140+
141+
1. Check for any worker, thread, or resource health problems by running the following query in SSMS:
142+
143+
```tsql
144+
/* ============================================================
145+
HEALTH CHECK (Worker, CPU, Memory)
146+
============================================================ */
147+
148+
SELECT
149+
Section,
150+
Metric,
151+
Value,
152+
ExtraInfo
153+
FROM (
154+
155+
/* ===============================
156+
WORKER THREAD STATUS
157+
=============================== */
158+
SELECT
159+
CAST('WORKER THREAD STATUS' AS VARCHAR(MAX)) AS Section,
160+
CAST(CONCAT('Scheduler ', scheduler_id) AS VARCHAR(MAX)) AS Metric,
161+
CAST(CONCAT('Workers: ', active_workers_count, '/', current_workers_count) AS VARCHAR(MAX)) AS Value,
162+
CAST(CONCAT('WorkQueue=', work_queue_count, ', Idle=', is_idle) AS VARCHAR(MAX)) AS ExtraInfo
163+
FROM sys.dm_os_schedulers
164+
WHERE scheduler_id < 255
165+
166+
UNION ALL
167+
168+
/* ===============================
169+
CPU PRESSURE
170+
=============================== */
171+
SELECT
172+
CAST('CPU PRESSURE' AS VARCHAR(MAX)) AS Section,
173+
CAST(CONCAT('Scheduler ', scheduler_id) AS VARCHAR(MAX)) AS Metric,
174+
CAST(CONCAT('RunnableTasks=', runnable_tasks_count) AS VARCHAR(MAX)) AS Value,
175+
CAST(CONCAT('PendingIO=', pending_disk_io_count) AS VARCHAR(MAX)) AS ExtraInfo
176+
FROM sys.dm_os_schedulers
177+
WHERE scheduler_id < 255
178+
179+
UNION ALL
180+
181+
/* ===============================
182+
MEMORY STATUS (System)
183+
=============================== */
184+
SELECT
185+
CAST('MEMORY STATUS' AS VARCHAR(MAX)) AS Section,
186+
CAST('SystemMemoryState' AS VARCHAR(MAX)) AS Metric,
187+
CAST(system_memory_state_desc AS VARCHAR(MAX)) AS Value,
188+
CAST(CONCAT('TotalMB=', total_physical_memory_kb/1024,
189+
', AvailableMB=', available_physical_memory_kb/1024) AS VARCHAR(MAX)) AS ExtraInfo
190+
FROM sys.dm_os_sys_memory
191+
192+
UNION ALL
193+
194+
/* ===============================
195+
PAGE LIFE EXPECTANCY
196+
=============================== */
197+
SELECT
198+
CAST('PAGE LIFE EXPECTANCY' AS VARCHAR(MAX)) AS Section,
199+
CAST('PLE' AS VARCHAR(MAX)) AS Metric,
200+
CAST(cntr_value AS VARCHAR(MAX)) AS Value,
201+
CAST(NULL AS VARCHAR(MAX)) AS ExtraInfo
202+
FROM sys.dm_os_performance_counters
203+
WHERE counter_name = 'Page life expectancy'
204+
AND object_name LIKE '%Buffer Manager%'
205+
206+
) AS x
207+
ORDER BY Section, Metric;
208+
```
209+
210+
Investigate the output of the health check query for any of the following problems as determined by the given symptoms:
211+
212+
- Worker thread pressure:
213+
- Worker exhaustion, for example `Workers: 512/512`.
214+
- `WorkQueue` is greater than zero. This value indicates that tasks are waiting and the system is overloaded.
215+
- CPU pressure:
216+
- `RunnableTasks` is greater than zero. This value indicates that a CPU bottleneck exists. A non-zero value can also indicate that the SQL Server scheduler is being monopolized by a thread (a non-yielding scheduler).
217+
- Memory pressure:
218+
- `Memory state` is `LOW`. This value indicates that the overall system is low on memory.
219+
- A low value for `AvailableMB`. This value indicates high memory usage for SQL Server.
220+
- A `PLE` value of less than 300. This value indicates high memory churn.
221+
1. If you identified any worker, CPU, or memory issues in the previous step, reduce your current workload to resolve the issues. If you didn't identify any issues, go to the next step.
222+
1. Restart the SQL Server Agent by running one of the following PowerShell commands:
223+
224+
> [!IMPORTANT]
225+
> Restarting the SQL Server Agent interrupts any currently running jobs.
226+
227+
- For default SQL Server instances:
228+
229+
```powershell
230+
Restart-Service -Name "SQLSERVERAGENT"
231+
```
232+
233+
- For named SQL Server instances:
234+
235+
```powershell
236+
Restart-Service -Name "SQLAgent$<InstanceName>"
237+
```
238+
239+
1. After SQL Server Agent restarts, verify that jobs are now running. Use the [Job Activity Monitor](/ssms/agent/monitor-job-activity#job-activity-monitor).
240+
241+
## Related content
242+
243+
- [SQL Server Agent overview](/ssms/agent/sql-server-agent)
244+
- [View the SQL Server Agent error log](/ssms/agent/view-sql-server-agent-error-log-sql-server-management-studio)
245+
- [Create a SQL Server Agent job](/ssms/agent/create-a-job)

support/sql/database-engine/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ items:
6969
items:
7070
- name: "Error 1053: The service did not respond to the start or control request in a timely fashion"
7171
href: agent/error-1053-service-did-not-start-timely.md
72+
- name: SQL Agent job fails with error 258
73+
href: agent/job-failed-error-258.md
7274

7375
- name: SQL Server resource usage (CPU, Memory, Storage) and Configuration
7476
items:

0 commit comments

Comments
 (0)