Dynamic SQL Agent Jobs - Schedule disabled before it can run (SetJobNextRunDate?)

  • Hi. I am running SQL 2012 sp2 64 bit (v 11.0.5343.0).

    I am dynamically creating SQL Agent jobs using TSQL, which need to be able to run once via schedule. I'm doing the usual thing of sp_add_job / sp_add_jobstep / sp_add_jobschedule / sp_add_jobserver etc, but it's not working reliably. If I put a delay of about 10 seconds on the start time on the scheduler then all seems to be ok. But otherwise the schedule is automatically disabled before the job runs, and so nothing happens.

    I've tried all sorts of things like setting up the schedule as disabled, adding the server, and then updating the scheduler to have the active start date/time (say) 5 seconds in the future and enabling at the same time. I still get the same results, as follows:

    In the error log I get the following message:

    [162] Internal request (from SetJobNextRunDate [reason: schedule will not run again]) to deactivate schedule 4534.

    The message usually appears in the log 1-2 seconds before the schedule is due to kick off and run the job. Grrr....

    I need to be able to get this running. Is there something I can do to inhibit the SetJobNextRunDate proc so it doesn't disable the schedule? I know it's trying to be helpful, but it's stopping me from doing what I need to!

    The last time I tried to do this was on SQL 2008 (pre SP2), and I didn't have any problems with it at all.

    Can anybody help?

    Many thanks for any help you can give.

  • I've has to do something similar in terms of enabling & disabling gobs based on various conditions... I found that adding a call to sp_start_job to the end of my enable scripts ensures that they start properly.

    It may very well work in your case as well.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply