Trans Pull Subscription Synchronize,在同步后终止程序

时间:2016-06-13 13:09:25

标签: c# sql replication

我在本地SQL Server实例上有一个SQL数据库,我将数据复制到另一个数据库,该数据库也在我的本地SQL Server Express实例上。

我使用以下代码进行同步操作:

        // 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();
        }

`

现在我的问题是当代理agent.Synchronize();运行,同步操作发生并成功完成,但程序终止。我多次检查数据库,并且每次都通过同步将新值传送到目标数据库。但是之后没有任何内容,Visual Studio Debugger就像没有发生任何事情一样停止,并且只留下这个输出消息:

程序'[13880] MyProgramm.vshost.exe:Program Trace'已退出,代码为0(0x0)。 程序'[13880] MyProgramm.vshost.exe'已退出,代码为-1073740777(0xc0000417)。

没有错误,没有例外。

关于为什么会发生这种情况的任何想法?

0 个答案:

没有答案