create procedure sys.sp_MSmergeagentjobcontrol
(
@publisher sysname,
@publisher_db sysname,
@publication sysname,
@subscriber sysname,
@subscriber_db sysname,
@action tinyint
)
as
begin
set nocount on
declare @job_id uniqueidentifier
declare @publisher_id int
declare @subscriber_id int
declare @retcode int
set @retcode = 0
set @publisher_id = null
select @publisher_id = server_id
from sys.servers
where upper(name) = upper(@publisher) collate database_default
if @publisher_id is null
begin
raiserror (21618, 16, -1, @publisher)
return 1
end
set @job_id = null
select @job_id = msma.job_id
from dbo.MSmerge_agents as msma
inner join msdb.dbo.sysjobs_view as sjv
on msma.job_id = sjv.job_id
inner join msdb.dbo.sysjobsteps as sjs
on sjv.job_id = sjs.job_id
where msma.publisher_id = @publisher_id
and msma.publisher_db = @publisher_db
and msma.publication = @publication
and upper(msma.subscriber_name) = upper(@subscriber)
and msma.subscriber_db = @subscriber_db
and sjv.category_id = 14
and sjs.subsystem = N'Merge'
if @job_id is null
begin
-- "Could not find a merge agent job for the specified merge push subscription."
raiserror(21847, 16, -1)
return 1
end
exec @retcode = sys.sp_MSreplicationagentjobcontrol
@job_id = @job_id,
@action = @action
return @retcode
end