SQL Server Agent – Fixing Job Next Run DateTime Stuck in the Past

sql serversql-server-agent

The job is enabled, the schedule is enabled, the agent service is running, but the job is not running as it is supposed to. Looking in the Job Activity Monitor, it shows a Next Run that is actually in the past.

Running the job manually will cause the Next Run to advance to the correct scheduled time for a new run, but when the time comes, the job still won't run.

How is this odd issue fixed?

Best Answer

This happened because you did a mass disable and then re-enable by updating the enabled flag in msdb.dbo.sysjobs after a massive outage; instead of doing things the right way and using the stored procedure, sp_update_job.

All of the jobs that were enabled one-by-one via the GUI worked fine, it was just those mass enabled that were a problem. Doing a quick disable then enable resolved all the issues.

See link for further info: https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-update-job-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15

Syntax:

EXEC dbo.sp_update_job  @job_name = N'[Your Job's Name HERE]',  
@enabled = 0 --- This disables, set to 1 to enable;

Don't update system tables directly next time.