June 13, 2012

sp_validate_replica_hosts_as_publishers (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_validate_replica_hosts_as_publishers(nvarchar @original_publisher
, nvarchar @publisher_db)

MetaData:

 --   
-- Name: sp_validate_replica_hosts_as_publishers
--
-- Descriptions: Retrieve the redirected publisher for the specified
-- publisher database pair. If the publisher is not
-- currently redirected, return NULL.
--
-- For redirected publishers, a connection is made to the
-- redirected publisher to determine whether the target of
-- redirection is an availability group VNN Name. If it is
-- not, a message is returned indicating that the redirected
-- publisher is not associated with an availability group.
--
-- The availability group primary is then queried for the
-- names of the hosts of the member replicas. Each host in
-- turn is validated as a publisher for the database.
--
-- In general, the stored procedure will attempt to continue
-- after encountering errors, and will try to validate all
-- of the known replica hosts associated with the availability
-- group.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success, 1 on failure; on failure errors are raised
--
-- Security: Public procedure invoked via RPC. check caller for db_owner
-- or in the PAL of a publication of the named pubisher check
--
create procedure sys.sp_validate_replica_hosts_as_publishers
(
@original_publisher sysname,
@publisher_db sysname,
@redirected_publisher sysname output
)
as
begin

set nocount on

declare
@target_server sysname,
@publisher_linked_server sysname,
@dbname sysname,
@retcode int,
@use_caller_credentials bit

set @redirected_publisher = null
set @target_server = null
set @publisher_linked_server = null
set @dbname = db_name()
set @use_caller_credentials = 1

-- Has to be executed from a distribution database
--
if (sys.fn_MSrepl_isdistdb (@dbname) <> 1)
begin
raiserror(21874, 16, -1, 'sys.sp_validate_replica_hosts_as_publishers', @dbname)
return 1
end

-- Verify input parameters are not NULL
--
if @original_publisher is null or
@publisher_db is null
begin
raiserror (21875, 16, -1, 'sys.sp_validate_replica_hosts_as_publishers')
return 1
end

-- Security check
--
if is_member(N'db_owner') <> 1
begin
exec @retcode = sys.sp_MSrepl_DistDBPALAccess @original_publisher

if (@retcode <> 0) or (@@error <> 0)
begin
raiserror (21873, 16, -1, 'sys.sp_validate_replica_hosts_as_publishers')
return 1
end
end

-- If the publisher of the database has not been redirected
-- return without performing any validation.
--
select @redirected_publisher = redirected_publisher
from MSredirected_publishers
where upper(original_publisher) = upper(rtrim(@original_publisher))
and publisher_db = rtrim(@publisher_db)

if @redirected_publisher is null
begin
raiserror(21871, 10, 0, @original_publisher, @publisher_db);
return 0
end

-- Verify that the original publisher is a SQL Server publisher of this
-- distributor.
--
if not exists (
select name from msdb.dbo.MSdistpublishers
where upper(rtrim(@original_publisher)) = upper(name) collate database_default
and N'MSSQLSERVER' = upper(publisher_type))
begin
raiserror (21876, 16, -1, @@servername, @original_publisher, @publisher_db)
return 1
end

-- Verify that there is a sysservers entry for the original publisher
-- at the distributor.
--
if not exists (
select srvid
from master..sysservers
where upper(srvname) collate database_default = upper(rtrim(@original_publisher)))
begin
raiserror (21877, 16, -1, @original_publisher, @publisher_db)
return 1
end

-- Create a linked server to connect to the target of redirection.
--
exec @retcode = sys.sp_hadr_create_linked_server @original_publisher, @publisher_db,
@redirected_publisher, @publisher_linked_server output, @use_caller_credentials
if @retcode <> 0
begin
return 1
end

-- Query the availability group primary for the names of the member replicas associated
-- with the publisher database and validate the host server for each replica as a
-- replication publisher.
--
exec @retcode = sys.sp_hadr_validate_replica_hosts_as_publishers @original_publisher,
@redirected_publisher, @publisher_db, @publisher_linked_server

return @retcode
end

No comments:

Post a Comment

Total Pageviews