-- This proc is called by distribution agent.
create procedure sys.sp_MSget_attach_state
@publisher sysname, -- publishing server name
@publisher_db sysname, -- publishing database name. If NULL then same as current db
@publication sysname, -- publication name,
@subscription_type int
AS
set nocount on
declare @retcode int
-- Security Check
-- We only run on subscriber so we only need sysadmin and dbo
exec @retcode = sys.sp_MSreplcheck_subscribe
if @@error <> 0 or @retcode <> 0
begin
return (1)
end
-- For non independent agent publications
if @publication is null or @publication = ''
set @publication = 'ALL'
select attach_state, attach_version from MSsubscription_agents
where UPPER(publisher) = UPPER(@publisher)
and publisher_db = @publisher_db
and publication = @publication
and subscription_type = @subscription_type