SQL server 2022 job fails
Hello
SQL Server 2022 16.0.4212.1 Installed in a windows server 2025 DC.
SQLSERVERAGENT starts with NT Service\SQLSERVERAGENT
I have some jobs that runs at the scheduled times.
But one no.
Failure: "Job failed. The job was invoked by Schedule 9 (06:00 xxxxx). The last step to execute was step 0 (no steps ran)."
Job steps: exec SP_01
GO
EXEC SP_02
But if I run it manually, it runs without problems. Can anyone help me?
Thank you
SQL Server | SQL Server Transact-SQL
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-09-11T21:22:09.7266667+00:00 "windows server 2025 DC" - does DC mean domain controller? That is not recommended.
When you say "run manually" do you mean that you start the job manually, or do you run the procedure directly?
In the same folder as the SQL Server errorlog, there is also SQLAGENT.OUT. Is there any information related to starting the job?
-
Delmira Oliveira • 100 Reputation points
2025-09-12T08:22:00.17+00:00 Hello Erland
You asked "When you say "run manually" do you mean that you start the job manually, or do you run the procedure directly?
----I start the job manually, not the procedure
the sqlagent.out:
2025-09-10 22:12:53 - ? [508] Logging SQL Server Agent messages in file 'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Log\SQLAGENT.OUT'.
2025-09-10 22:12:53 - ? [000] Event Global\sqlserverRecComplete opened
2025-09-10 22:12:53 - ? [100] Microsoft SQLServerAgent version 16.0.4212.1 (X64 unicode retail build) : Process ID 10252
2025-09-10 22:12:53 - ? [495] The SQL Server Agent startup service account is NT Service\SQLSERVERAGENT.
2025-09-10 22:12:56 - ? [393] Waiting for SQL Server to recover database 'msdb'...
2025-09-10 22:12:58 - ? [000]
2025-09-10 22:12:59 - ? [101] SQL Server SrvSom version 16.00.4212 (0 connection limit)
2025-09-10 22:12:59 - ? [102] SQL Server ODBC driver version 17.10.006
2025-09-10 22:12:59 - ? [103] NetLib being used by driver is DBNETLIB; Local host server is SRVSOM
2025-09-10 22:12:59 - ? [310] 32 processor(s) and 65294 MB RAM detected
2025-09-10 22:12:59 - ? [339] Local computer is xx running Windows Server 2025 Standard 10.0 (26100)
2025-09-10 22:13:00 - ? [432] There are 7 subsystems in the subsystems cache
2025-09-10 22:13:01 - ? [129] SQLSERVERAGENT starting under Windows NT service control
2025-09-10 22:13:01 - ? [000] InitDefaultMSDBId initialized default msdb id to 4.
2025-09-10 22:13:04 - ? [353] Mail session started
2025-09-10 22:13:04 - + [396] An idle CPU condition has not been defined - OnIdle job schedules will have no effect
I will set set CPU idle time and duration in the SQL Server Agent.
I will report the result
Thanks
-
Delmira Oliveira • 100 Reputation points
2025-09-12T08:38:59.62+00:00 I I've read the configuration more closely, and it won't solve the problem at all.
This job is actually the first one to be executed daily, at 6:00 AM.
-
Delmira Oliveira • 100 Reputation points
2025-09-12T08:54:09.07+00:00 I I've read the configuration more closely, and it won't solve the problem at all.
This job is actually the first one to be executed daily, at 6:00 AM.
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-09-12T13:24:14.2833333+00:00 You did not answer the question about the domain controller.
I've never seen or heard about a job failing at step 0, so I am quite a bit in the dark here. I googled on the error message, but all I found was that you had posted the same question in two more places, and there was not any satisfactory reply in any of them.
A common approach to get better diagnostics is to define an output file, but you do that on the job step, and you are not coming that far.
The one thing I would try - just as a desperate guess - is to move the start of the job 10-15 minutes later, in case there is a clash with something else.
Another idea is to set up an extended-events session to see if there are any exceptions around this time that could explain why the job does not start. I have an article on my web site Monitor Exceptions in Your Database where I describe how to set up such a session and also present a view to look at the data.
-
Delmira Oliveira • 100 Reputation points
2025-09-12T13:35:56.91+00:00 Hello
"You refer, that I did not answer the question about the domain controller"
... We have a series of jobs running. Another one whose only step call another procedure on the same database and runs without problems. So I think it has nothing to do with the account that starts the service.
I'll run some tests this weekend. I'll share something on Monday.
Thanks
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-09-12T13:39:24.6766667+00:00 "You refer, that I did not answer the question about the domain controller"
And you still have not. Well, you don't have to. But if it is a domain controller, that could be part of the problem.
Whether jobs run a procedure or not may not matter, since it fails before it attempts to start any steps.
And you are right, that idle condition in the SQL Agent log is not likely to have anything to do with it. I only asked you to look there with the hope that there might be some clues there.
-
Delmira Oliveira • 100 Reputation points
2025-09-12T14:32:21.43+00:00 About the account service. I do not want to belittle your help, but how to explain that 10 other JBOS run at the respective scheduled times?
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-09-12T17:04:15.3033333+00:00 Apparently something is going on at a six o'clock in the morning. What, I don't have the faintest. But running SQL Server on a domain controller has never been a good idea, and the issue could be related to this. As long as we don't have a better error message, we are just fumbling in the dark.
-
Delmira Oliveira • 100 Reputation points
2025-09-16T17:11:05.6733333+00:00 Hello
Many tests performed.
I created two independent tasks do type (T-SQL) , each calling one of the two Store procedures. They failed.
I executed then the Store procedures directly and saved each generated SQLquery in two SQL files.
I created two tasks, each with a step of the type (operating system - (cmdexec) and with the command = sqlcmd -S XXXXX -i ".......................file.sql") --- It works.
I ran lab on another machine, running Windows 11 Pro and also with SQL 2022 Standard.
I created the database in question and restored it from a recent backup.
Everything worked exactly as described above, even when I set a Windows account to start the agent service.
This database was on a server running SQL Standard 2017 and Windows Server 2012. Now it's on SQL 2022 Standard running on Windows Server 2025vStd.
I'm clueless!
-
Delmira Oliveira • 100 Reputation points
2025-09-16T17:14:59.41+00:00 Hello
Hello
Many tests performed.
I created two independent tasks do type (T-SQL) , each calling one of the two Store procedures. They failed.
I executed then the Store procedures directly and saved each generated SQLquery in two SQL files.
I created two tasks, each with a step of the type (operating system - (cmdexec) and with the command = sqlcmd -S XXXXX -i ".......................file.sql") --- It works.
I ran lab on another machine, running Windows 11 Pro and also with SQL 2022 Standard.
I created the database in question and restored it from a recent backup.
Everything worked exactly as described above, even when I set a Windows account to start the agent service.
This database was on a server running SQL Standard 2017 and Windows Server 2012. Now it's on SQL 2022 Standard running on Windows Server 2025vStd.
I'm clueless!
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-09-16T20:46:27.9+00:00 Since the job fails on "step 0", that is before any step is started, I can't see that the contents of the job matters. The job could read "PRINT 'Hello world!'" and it would not be any better.
Did you set up the extended-event session that I suggested? I think that if you can capture any error that is raised, this can help us to get out of the dark. (But if there is an error happening outside SQL Server, we will not see it this way.)
Trying this and that blindly is tedious and can really be a waste of time. At least if there is a way to get hold of the actual error. Which I suggest that there might be.
Then again, if I understand this correctly, you can get the job to run if you set it up as a CmdExec job step. If that is an acceptable workaround to you, maybe it is time to move on to other pressing tasks.
-
Delmira Oliveira • 100 Reputation points
2025-09-17T07:10:03.23+00:00 Hello Erland
You refer "I have an article on my web site Monitor Exceptions in Your Database"
--- I think the link is not correct
I am interested in knowing the cause of this situation
Thanks
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-09-17T10:42:54.37+00:00 You refer "I have an article on my web site Monitor Exceptions in Your Database" --- I think the link is not correct
Sorry about that! Here is the correct link: https://www.sommarskog.se/Short%20Stories/trace-exceptions.html
-
Delmira Oliveira • 100 Reputation points
2025-09-17T19:22:41.0666667+00:00 About your "Monitor Exceptions in Your Database"
-- I can not found Extended Events in Object Explorer. I have sql 2022 Std. I connect to the Data Base Engine with sa.
My SMSS, version 20.2.1
Do
-
Delmira Oliveira • 100 Reputation points
2025-09-17T20:47:15.89+00:00 I already found
-
Delmira Oliveira • 100 Reputation points
2025-09-18T10:53:46.0433333+00:00 Hello
I tried to recreate a session based on your Monitor Exceptions in Your Database, but nothing appears in the live data. I configured the session to start when the server starts.
When I opened the .xel file, it showed 0 events.
What I made wrong?
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-09-18T20:30:46.7366667+00:00 Maybe you don't have any exceptions? To verify that the session works, open a command-line window and run:
SQLCMD -S Yourserver -Q"Bad query"This produces an exception that should appear in the view. Or in Live Data if you look there. (The reason you should not do this from SSMS is that the session has a filter for SSMS.)
If the Bad query appears in the X-event session and the job has failed since you started the session, this suggests that it is not failing inside SQL Server.
-
Delmira Oliveira • 100 Reputation points
2025-10-21T08:34:08.18+00:00 Hello again
As I mentioned, there are several jobs whose steps call Store Procedures from a given database.
All Store Procedures were programmed for the first time on a SQL Server 2017 Std, on an HP Server DL 320 G9, ruuning windows server 2012.
A new server (HP DL 380 G11) was purchased, running Windows Server 2025 Standard and SQL Server 2022 (RTM-CU20-GDR) (KB5065220) - 16.0.4212.1 (x64).
The database in question was created and restored based on the last backup made on the old server.
As I mentioned, most Jobs' steps (excluding backup jobs) call multiple Store Procedures.
And even those that usually fail, sometimes run automatically and manually with sucess.
In a lab I ran on a different computer but and with the same SQL servsion, I had access to "modify" the stored procedures to adjust them to the new machine.
The stored procedure programmer did something that made the "modify" option inactive. This prevents me from continuing the lab. Is there any way to reactivate this option?
There's also another Store Procedure that runs monthly, and the first execution on the new server failed.
It failed with the same message (Failure: "Job failed. The job was invoked by Schedule 9 (06:00 xxxxx). The last step to execute was step 0 (no steps ran).")
On the lab computer, and with the database before the "modify" SP option was disabled, I can modify it, and it runs smoothly. This stored procedure executes: "'queryout "' + @filePath + '" -c -t ";" -U sa -P password -S SQL server IP -C 65001' EXEC xp_cmdshell @sqlCmd, NO_OUTPUT The filepath is exactly the same as the server's.
I just change the SQL server's IP. It runs without problems.
On the real server, it fails.
Am I experiencing any bugs (Processor with P67092-B21, 16 Cores) / Windows Server 2025 Standard / Windows SQL Server 2022?
Thanks and best regards
DO
-
Erland Sommarskog • 127.4K Reputation points • MVP • Volunteer Moderator2025-10-21T20:57:34.4433333+00:00 Since the job fails on "step 0" and does not run any steps, the stored procedure does not matter.
In any case, I would recommend you do to open a support case. To get help in a forum, you will need to run troubleshooting steps on your own from our instructions. It seems that you are not really on the level where this works well. A support engineer can devote more time to the case, and can also get more direct access to your environment that is possible in a public forum.
Sign in to comment