Reputation: 515
I am writing a program using RedGate SQL Compare that syncs data between nodes in a transactional replication topology. In cases where there are more than 2 nodes, I need an automated way of creating pairings of SQL instance/database name so that I can sync all the links in the tree.
I believe this information is stored in the distribution database. I have found tables that contain the names of the publication database and subscription database (MSsubscriptions).
However, although publisher_id and subscriber_id are listed as fields, I don't see how I can use that to get the names of the SQL instances.
The MSsubscriber_info in the distribution database contains the SQL instance names of the publishers, but there is no ID column.
Does anyone know how I can obtain the publisher matched with the publication database? I would appreciate any advice anyone can give. Thanks.
Upvotes: 1
Views: 8289
Reputation: 4693
The information you're looking for is in master.sys.servers
So you'd join the publisher_id and subscriber_id from the MSsubscriptions
on server_id
in the servers
table. This should be a good starting point for you (assuming SQL Server 2005 or greater)
select distinct pub.name, sub.name
from master.sys.servers pub
join distribution.dbo.MSsubscriptions s
on s.publisher_id = pub.server_id
join master.sys.servers sub
on s.subscriber_id = sub.server_id;
Upvotes: 2