Changing the schedule of the Snapshot agent

Posted on 2002-05-30
Last Modified: 2008-02-07
I have transactional replication working pretty well.  I wrote this VB utility that allows the users to manage some of the publication articles.  Once again working pretty well.  There is one piece I can't seem to find any help on.  

After a new article is added via the utility, I want to change the schedule detail of the snapshot agent to run at 1am of the next day.  If at all possible I would like to do this using the system stored procedures and not a DMO or an ActiveX object.  What do ya think, is it possible?

Question by:Steve Sirica
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 7045189
The snap shot agent is manifested as scheduled job on the server, so look at sp_Update_JobSchedule in the BOL. This should give you all the resources necessary to change the schedule.  Actually I would use sp_Add_JobSchedule to add a second schedule to the job to run once at 1 AM on the next day and then enable it.  

You'll need to get the name or id of the job by looking through the jobs in Enterprise Manager once replication has been set up. And possibly the schedule ID - depending on how you want to implement this.  Sounds like fun, let me know how this turns out . . .


Accepted Solution

bsnyder earned 100 total points
ID: 7045341
Here is part of the script I used in a cursor to stagger the time these jobs run.
You will probably want to get rid of the cursor, and add code to find just one database's replication snapshot job.

DECLARE @snap_name NVARCHAR(100),
        @failures  SMALLINT,
        @goodretry SMALLINT,
        @goodsched SMALLINT,
        @StartTime INT,
        @cr CURSOR
SET @failures  = 0
SET @goodretry = 0
SET @goodsched = 0
SET @StartTime = 200100   -- HHMMSS 8:01 pm

     FROM   msdb.dbo.sysjobs WHERE category_id = 15 ORDER BY name
OPEN @cr
FETCH NEXT FROM @cr INTO @snap_name
     DECLARE @ReturnCode INT
     SELECT  @ReturnCode = 0

     -- change job schedule
     EXECUTE @ReturnCode = msdb.dbo.sp_update_jobschedule @job_name = @snap_name,
                           @name = N'Replication Agent Schedule.',
                           @enabled = 1,
                           @freq_type = 4,
                           @active_start_time = @StartTime, -- was 70000 for 7:00 am,
                           @freq_interval = 1,
                           @freq_subday_type = 1,       -- was 8 for hours
                           @freq_subday_interval = NULL, -- was 12 Number of hours between runs
                           @freq_relative_interval = 1,
                           @freq_recurrence_factor = 0,
                           @active_end_date = 99991231,
                           @active_end_time = 220000
     IF (@@ERROR <> 0 OR @ReturnCode <> 0)
          SET @failures = @failures + 1
          SET @goodsched = @goodsched + 1
     SET @StartTime = @StartTime + 100 -- add 1 minutes
     FETCH NEXT FROM @cr INTO @snap_name


Author Comment

by:Steve Sirica
ID: 7045397

Thanks, with a little tweaking I got that code to do exactly what I was looking to do.  

Thanks again,

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question