Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

Trans Pull Subscription Synchronize, Terminates the program after Synchronization

$
0
0

I have an SQL Data base on my local SQL Server Instance, and I replicate data to another Data Base which is on also on my local SQL Server Express instance .

I use the following code to make the Synchronization operation happen :

        // Define server, publication, and database names.
        String subscriberName = Environment.MachineName + "\\SQLEXPRESS";
        // String subscriberName = "(LocalDB)\v11.0";

        String publisherName = ConfigurationManager.AppSettings["PublisherName"].ToString();
        String publicationName = ConfigurationManager.AppSettings["PublicationName"].ToString();
        String publicationDbName = ConfigurationManager.AppSettings["PublicationDbName"].ToString();
        String subscriptionDbName = ConfigurationManager.AppSettings["SubscriptionDbName"].ToString();

        // Create a connection to the Subscriber.
        ServerConnection conn = new ServerConnection(subscriberName);
        ServerConnection connPublish = new ServerConnection(publisherName, "sa", "mypassword");
        TransPullSubscription subscription;

        try
        {
            // Connect to the Subscriber.
            conn.Connect();
            // Define subscription properties.
            subscription = new TransPullSubscription();
            subscription.ConnectionContext = conn;
            subscription.DatabaseName = subscriptionDbName;
            subscription.PublisherName = publisherName;
            subscription.PublicationDBName = publicationDbName;
            subscription.PublicationName = publicationName;
            subscription.CreateSyncAgentByDefault = true;

            // If the pull subscription and the job exists, start the agent job.
            if (subscription.LoadProperties() && subscription.AgentJobId != null)
            {
                Microsoft.SqlServer.Replication.TransSynchronizationAgent agent = subscription.SynchronizationAgent;
                agent.Synchronize();
            }
            else
            {
                // Do something here if the subscription does not exist.
                throw new ApplicationException(String.Format(
                    "A subscription to '{0}' does not exists on {1}",
                    publicationName, subscriberName));
            }
        }
        catch (Exception ex)
        {
            ReturnValue = false;
        }
        finally
        {
            conn.Disconnect();
        }

`

Now my problem is that when the code agent.Synchronize(); runs, the Synchronization operation happens and completes successfully, but the program terminates. I checked the Data base many times and in each times the new values come to the destination DB via Synchronization. But nothing after, Visual Studio Debugger stops as if nothing happened, and leaves me with only this output message :

The program '[13880] MyProgramm.vshost.exe: Program Trace' has exited with code 0 (0x0). The program '[13880] MyProgramm.vshost.exe' has exited with code -1073740777 (0xc0000417).

No error,no exception.

Any ideas on why is this happening ?


Viewing all articles
Browse latest Browse all 17268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>