Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Changing the schedule of the Snapshot agent

Posted on 2002-05-30
3
Medium Priority
?
547 Views
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?

Steve
0
Comment
Question by:Steve Sirica
3 Comments
 
LVL 5

Expert Comment

by:spcmnspff
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 . . .


0
 

Accepted Solution

by:
bsnyder earned 400 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

SET @cr = CURSOR FAST_FORWARD LOCAL FOR
     SELECT DISTINCT name
     FROM   msdb.dbo.sysjobs WHERE category_id = 15 ORDER BY name
OPEN @cr
FETCH NEXT FROM @cr INTO @snap_name
WHILE @@FETCH_STATUS = 0
  BEGIN
     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
     ELSE
          SET @goodsched = @goodsched + 1
     SET @StartTime = @StartTime + 100 -- add 1 minutes
     FETCH NEXT FROM @cr INTO @snap_name
  END
CLOSE @cr
DEALLOCATE @cr

0
 
LVL 4

Author Comment

by:Steve Sirica
ID: 7045397
bsnyder,

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

Thanks again,
Steve
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

572 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