April 30, 2012

sp_helpsubscriptionerrors (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_helpsubscriptionerrors(nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication
, nvarchar @subscriber
, nvarchar @subscriber_db)

MetaData:

 CREATE PROCEDURE sys.sp_helpsubscriptionerrors  
(
@publisher sysname,
@publisher_db sysname,
@publication sysname,
@subscriber sysname,
@subscriber_db sysname
)
AS
BEGIN
DECLARE @retcode int,
@publisher_id int,
@subscriber_id int,
@agent_id int

-- database must be distribution db
IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
BEGIN
RAISERROR (21482, 16, -1, 'sp_helpsubscriptionerrors', 'distribution')
RETURN 1
END

-- retrieve pub/sub/agent id
SELECT @publisher_id = server_id
FROM sys.servers
WHERE UPPER(name) = UPPER(@publisher)

SELECT @subscriber_id = server_id
FROM sys.servers
WHERE UPPER(name) = UPPER(@subscriber)

SELECT @agent_id = id
FROM MSdistribution_agents
WHERE publisher_id = @publisher_id
AND publisher_db = @publisher_db
AND (publication = @publication
OR lower(publication) = N'all')
AND subscriber_id = @subscriber_id
AND subscriber_db = @subscriber_db

-- PAL Security Check
EXEC @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id,
@agent_type = 0 -- distribution agent
IF @@ERROR <> 0 OR @retcode <> 0
RETURN 1

-- return the resultset
SELECT msre.*
FROM MSrepl_errors msre
WHERE msre.id IN (SELECT error_id
FROM MSdistribution_history
WHERE agent_id = @agent_id)
ORDER by msre.time desc

RETURN 0
END

No comments:

Post a Comment

Total Pageviews