create procedure sys.sp_MSrepl_subscriptionagentjobcontrol
(
@publication sysname,
@subscriber sysname,
@subscriber_db sysname,
@publisher sysname,
@publisher_type sysname,
@action tinyint
)
as
begin
set nocount on
declare @PUSH int
set @PUSH = 0
declare @retcode int
declare @independent_agent int
declare @pubid int
declare @distributor sysname
declare @distributor_rpc sysname
declare @distribution_db sysname
declare @publisher_db sysname
declare @subscriber_id int
declare @procedure nvarchar(4000)
declare @start tinyint
set @retcode = 0
set @independent_agent = 0
set @pubid = null
set @publisher_db = db_name()
set @start = 0
-- Security check
exec @retcode = sys.sp_MSreplcheck_publish
if @@error <> 0 or @retcode <> 0
return 1
-- Check to see if database is activated for publication
if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
begin
-- "This database is no enabled for publication."
raiserror (14013, 16, -1)
end
-- Parameter check: @publication
if @publication is null
begin
-- "The parameter @publication cannot be NULL."
raiserror (14043, 16, -1, '@publication', 'sp_MSrepl_startsubscription_agent')
return 1
end
exec @retcode = sys.sp_validname @publication
if @@error <> 0 or @retcode <> 0
return 1
-- Parameter Check : @publisher
if @publisher is null
begin
set @publisher = publishingservername()
end
-- Retrieve publication options
select @pubid = pubid,
@independent_agent = independent_agent
from dbo.syspublications
where name = @publication
and pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)
if @pubid is null
begin
-- "The publication '@publication' does not exist."
raiserror (20026, 16, -1, @publication)
return 1
end
-- Check to see if the subscription exists
if not exists (select ss.*
from sysextendedarticlesview seav
join syssubscriptions ss
on ss.artid = seav.artid
where seav.pubid = @pubid
and ss.srvname = upper(@subscriber)
and ss.dest_db = @subscriber_db
and subscription_type = @PUSH)
begin
-- "The subscription could not be found."
raiserror (20021, 16, -1)
return 1
end
exec @retcode = sys.sp_helpdistributor
@rpcsrvname = @distributor_rpc output,
@distribdb = @distribution_db output,
@publisher = @publisher
if @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
begin
-- "The Distributor has not been installed correctly."
raiserror (20036, 16, -1)
return 1
end
if @independent_agent = 0
begin
set @publication = 'ALL'
end
set @procedure = quotename(rtrim(@distributor_rpc)) + '.' + quotename(rtrim(@distribution_db)) + case when @action = @start then '.sys.sp_MSstartdistribution_agent' else '.sys.sp_MSstopdistribution_agent' end
exec @retcode = @procedure
@publisher = @publisher,
@publisher_db = @publisher_db,
@publication = @publication,
@subscriber = @subscriber,
@subscriber_db = @subscriber_db
return @retcode
end