Question

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.

Was it helpful?

Solution

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...
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top