create procedure sys.sp_MSrepl_publicationsnapshotjobcontrol
(
@publication sysname,
@publisher sysname,
@action tinyint
)
as
begin
set nocount on
declare @retcode int
declare @tranpub_found bit
declare @mergepub_found bit
declare @dbname sysname
declare @start tinyint
set @retcode = 0
set @tranpub_found = 0
set @mergepub_found = 0
set @dbname = db_name()
set @start = 0
if @publisher is null
set @publisher = publishingservername()
exec @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_MSrepl_publicationsnapshotjobcontrol'
if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 return @retcode end
exec @retcode = sys.sp_MSreplcheck_publish
if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 return @retcode end
if sys.fn_MSrepl_ispublished(@dbname) != 1
begin
raiserror (18757, 16, -1)
return (1)
end
if sys.fn_MSrepl_istranpublished(@dbname, 1) = 1
begin
if exists (select * from dbo.syspublications where name = @publication)
begin
set @tranpub_found = 1
end
end
if sys.fn_MSrepl_ismergepublished(@dbname) = 1
begin
if exists (select * from dbo.sysmergepublications where name = @publication and publisher_db = @dbname and upper(publisher) = upper(@publisher))
begin
set @mergepub_found = 1
end
end
if @tranpub_found = 0 and @mergepub_found = 0
begin
raiserror (15001, 11, -1, @publication)
return (1)
end
declare @distributor sysname
declare @distribdb sysname
declare @dist_rpcname sysname
declare @distproc nvarchar(4000)
declare @pubtype sysname
set @distproc = N''
set @pubtype = null
exec @retcode = sys.sp_MSrepl_getdistributorinfo
@publisher = @publisher,
@distributor = @distributor output,
@distribdb = @distribdb output,
@rpcsrvname = @dist_rpcname output,
@publisher_type = @pubtype output
if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 return @retcode end
if (@publisher is not null) and (@pubtype is null or @distribdb is null or @distributor is null)
begin
raiserror (21600, 16, -1, @publisher)
return (1)
end
set @distproc = quotename(rtrim(@dist_rpcname)) + '.' + quotename(@distribdb) + case when @action = @start then '.sys.sp_MSstartsnapshot_agent' else '.sys.sp_MSstopsnapshot_agent' end
exec @retcode = @distproc
@publisher = @publisher,
@publisher_db = @dbname,
@publication = @publication
return @retcode
end