create procedure sys.sp_MSpullsubscriptionagentjobcontrol
(
@publisher sysname,
@publisher_db sysname,
@publication sysname,
@action tinyint
)
WITH EXECUTE AS 'dbo'
as
begin
set nocount on
declare @retcode int
declare @job_id uniqueidentifier
declare @subscription_type int
set @retcode = 0
set @job_id = null
set @subscription_type = null
if object_id('dbo.MSreplication_subscriptions') is null
begin
raiserror (20017, 16, -1)
return 1
end
-- Subscription existence check
select @subscription_type = subscription_type
from dbo.MSreplication_subscriptions
where upper(publisher) = upper(@publisher)
and publisher_db = @publisher_db
and publication = @publication
if @subscription_type is null
begin
raiserror (20017, 16, -1)
return 1
end
if @subscription_type = 0
begin
raiserror (21001, 16, -1)
return 1
end
if object_id('dbo.MSsubscription_properties') is not null
begin
select @job_id = sjs.job_id
from MSsubscription_properties sp
inner join msdb.dbo.sysjobsteps sjs
on sp.job_step_uid = sjs.step_uid
inner join msdb.dbo.sysjobs_view sjv
on sjv.job_id = sjs.job_id
where upper(publisher) = upper(@publisher)
and publisher_db = @publisher_db
and publication = @publication
and sjv.master_server = 0
and sjv.category_id = 10
and sjs.subsystem = N'Distribution'
and (sjs.database_name is null or sjs.database_name = db_name())
end
if @job_id is null
begin
-- "The specified pull subscription is not configured with a synchronization agent job."
raiserror(21848, 16, -1)
return 1
end
exec @retcode = sp_MSreplicationagentjobcontrol
@job_id = @job_id,
@action = @action
return @retcode
end