Solved

Changing the schedule of the Snapshot agent

Posted on 2002-05-30
3
500 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 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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now