Sql-server – SQL Agent Jobs hanging at last Run date and time

sql-server-agent

For maintenance tasks on my LogShipped environment I run T-SQL script to disable the copy/restore agent job for the duration of maintenance and then enable when done.
When I enable the jobs via TSQL it seems the schedule hangs (at last run date) and does not execute future schedules and LS DBs fall out of sync. Restarting the SQL Agent & manual start of the job resolves the issues ok.

SQL Server 2016 SP1.
Using msdb..sysjobs to disable/enable the job and
msdb..sysjobschedule to disable/enable the schedule

Anyone any ideas?

Best Answer

Are you using this correct way for disable jobs?

USE msdb ;
GO
EXEC dbo.sp_update_job
@job_name = N'NameOgYourJob',
@enabled = 0 ;
GO

You don't have to update with update statement, it's describe HERE and HERE