Adsense

Wednesday, February 5, 2014

Disable all snapshots on a distributor

When creating replication from script I find that the snapshot agents are enabled and scheduled to run on the hour.  To prevent them from pounding the database and running you need to disable them.  If you have a lot of snapshot agents disabling them all through the GUI can take a long time.  The script below will disable all snapshot agents.


declare @sql nvarchar(1000)

declare curs cursor for
select 'EXEC msdb.dbo.sp_update_job @job_id=N''' + cast(job_id as varchar(100)) + ''', @enabled=0'
from msdb.dbo.sysjobs where date_created > '12/03/2013' and enabled = 1 and category_id = 15 --snapshot'

open curs

fetch next from curs into @sql

while @@FETCH_STATUS = 0
begin
print @sql

exec sp_executesql @sql

fetch next from curs into @sql
end

close curs

deallocate curs

No comments:

Post a Comment