Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing the schedule of the Snapshot agent

Posted on 2002-05-30
3
Medium Priority
?
544 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
[X]
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
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

597 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