Using RMO, how can I get the list of Local Subscriptions from SQL Server?

孤人 提交于 2020-01-05 06:27:29

问题


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.


回答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...
    }
}


来源:https://stackoverflow.com/questions/13481091/using-rmo-how-can-i-get-the-list-of-local-subscriptions-from-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!