I am trying to set up replication between SQL Server 2012 and SQL Server Express 2012. I've set up the publication and the subscriptions through SSMS, and am trying to get syncing done via RMO.
I've followed the answer here, and I get an error saying that the subscription I'm trying to sync doesn't exist. I tried this to examine the list of subscriptions on the subscriber, and it is empty.
But I can see the subscription in SSMS. It's right there looking at me. I must be missing something about how to set these up. I have already deleted and recreated both the publication and the subscription. No luck.
Updated: Changed the example code to look for TransPullSubscriptions. The code from the second link now correctly prints the subscription.
The code to actually run the sync, however, still does not see the subscription on the server.
The test for load properties fails, but continuing on throws an error: "SynchronizationAgent" can only be used if the object presents an existing object in the server.
Updated: now with MORE code!
static void SynchronizeMergePullSubscriptionViaRMO()
{
// Define the server, publication, and database names.
string subscriberName = "testsubDBserver";
string publisherName = "testpubDBserver";
//string distributorName = "distribution";
string publicationName = "test_sub";
string subscriptionDbName = "Data";
string publicationDbName = "Data";
// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);
TransPullSubscription subscription;
TransSynchronizationAgent agent;
try
{
// Connect to the Subscriber.
conn.Connect();
// Define the pull subscription.
subscription = new TransPullSubscription();
subscription.ConnectionContext = conn;
subscription.DatabaseName = subscriptionDbName;
subscription.PublisherName = publisherName;
subscription.PublicationDBName = publicationDbName;
subscription.PublicationName = publicationName;
// If the pull subscription exists, then start the synchronization.
if (!(subscription.LoadProperties()))
{
// Get the agent for the subscription.
agent = subscription.SynchronizationAgent;
// Set the required properties that could not be returned
// from the MSsubscription_properties table.
//agent.PublisherSecurity = SecurityMode.Integrated;
agent.DistributorSecurityMode = SecurityMode.Integrated;
agent.Distributor = publisherName;
// Enable verbose merge agent output to file.
agent.OutputVerboseLevel = 4;
agent.Output = "D:\\logs\\mergeagent.log";
// Synchronously start the Merge Agent for the subscription.
agent.Synchronize();
}
The answer is to check your work for typos again even after you are completely certain that everything is spelled correctly. testpubDBserver != testpubBDserver.
Thanks to Brandon for his help.