使用SQL Server Management Studio中,很容易看到下复制文件夹的用户数据库本地订阅的名单。我的问题是我如何得到该列表编程。我知道,我可以使用RMO来创建预订。我想知道如何让所有的现有本地订阅的列表。
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.
的 Publication.EnumSubscriptions方法返回订阅刊物的订阅。这将是在执行sp_helpsubscription或sp_helpmergesubscription相当于
The Publication.EnumSubscriptions Method returns the subscriptions that subscribe to a publication. This would be the equivalent of executing sp_helpsubscription or sp_helpmergesubscription.
您还可以连接到订阅服务器,获得 ReplicationDatabaseCollection ,并列举通过复制数据库的订阅。下面是一个例子:
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...
}
}