1

Using SQL Server Management Studio, it is easy to see the list of of Local Subscriptions on the subscriber database under the Replication folder. My question is how do I get that list programmatically . I know that I can use RMO to create a subscription. I want to know how to get a list of all of the existing Local Subscriptions.

epotter
  • 7,631
  • 7
  • 63
  • 88
  • It can be useful to somebody (like me) to know how to do this without RMO. exec sp_helpreplicationdboption @reserved = 1 – Alsin Mar 22 '13 at 21:41

1 Answers1

1

The Publication.EnumSubscriptions Method returns the subscriptions that subscribe to a publication. This would be the equivalent of executing sp_helpsubscription or sp_helpmergesubscription.

You can also connect to a Subscriber, get the ReplicationDatabaseCollection, and enumerate through the replicated databases subscriptions. Here is an example:

// Connect to the Subscriber
subscriberName = "SubscriberName";
subscriberConnection = new ServerConnection(subscriberName);
subscriberConnection.Connect();

// Get Subscriber replication databases
ReplicationServer subscriberServer = new ReplicationServer(subscriberConnection);
ReplicationDatabaseCollection subscriberReplicationDatabases = subscriberServer.ReplicationDatabases;

// Enumerate Subscriber replication databases
foreach (ReplicationDatabase subscriptionDatabase in subscriberReplicationDatabases)
{
    foreach (MergePullSubscription mergePullSubscription in subscriptionDatabase.MergePullSubscriptions)
    {
        // do something...
    }
}
Brandon Williams
  • 3,695
  • 16
  • 19
  • This works when you are connected to the publisher database. But it doesn't seem to work when you are connected to the subscriber database. – epotter Nov 20 '12 at 21:32
  • Hi @epotter, I added an example how to connect to the Subscriber and enumerate through the local subscriptions. – Brandon Williams Nov 20 '12 at 22:50