0

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();
            }
Community
  • 1
  • 1
Andrew Martin
  • 151
  • 3
  • 10
  • My example here (http://stackoverflow.com/questions/13481091/using-rmo-how-can-i-get-the-list-of-local-subscriptions-from-sql-server) is looking for Merge pull subscriptions. Did you modify it to look for Transactional pull subscriptions? – Brandon Williams Feb 24 '14 at 19:40
  • Updated to respond to your comment and add a code example. – Andrew Martin Feb 24 '14 at 21:43
  • Getting closer. Can I see the code before subscription.LoadProperties() please? – Brandon Williams Feb 24 '14 at 21:47
  • Sure thing. That's all of it really. Except for where I catch the exception. – Andrew Martin Feb 24 '14 at 22:38
  • Is the publication name really "test_sub"? – Brandon Williams Feb 24 '14 at 23:21
  • 1
    To start off, please verify that your subscriberName, publisherName, publicationName, subscriptionDBName, and publicationDBName are set correctly. If those are correct, then subscription.LoadProperties() will return true if the subscription exists on the server and everything else will work. – Brandon Williams Feb 24 '14 at 23:51
  • 1
    Yes. Those actually are my test values. But you are right, and I had a small typo between my pub database and my settings here. It works now. Thank you for your help. How do I mark this question as answered? – Andrew Martin Feb 25 '14 at 17:01

1 Answers1

1

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.

Andrew Martin
  • 151
  • 3
  • 10