0

SQL Server 2012 と SQL Server Express 2012 の間でレプリケーションをセットアップしようとしています。SSMS を介してパブリケーションとサブスクリプションをセットアップし、RMO を介して同期を実行しようとしています。

こちらの回答に従いましたが、同期しようとしているサブスクリプションが存在しないというエラーが表示されます。サブスクライバーのサブスクリプションのリストを調べるためにこれを試しましたが、空です。

しかし、SSMS でサブスクリプションを確認できます。そこにいて私を見ている。これらの設定方法について何かが欠けているに違いありません。パブリケーションとサブスクリプションの両方を既に削除して再作成しました。運がない。

更新: TransPullSubscriptions を探すようにサンプル コードを変更しました。2 番目のリンクのコードは、サブスクリプションを正しく出力するようになりました。

ただし、実際に同期を実行するコードは、サーバー上のサブスクリプションをまだ認識していません。

ロード プロパティのテストは失敗しますが、続行するとエラーがスローされます。「SynchronizationAgent」は、オブジェクトがサーバー内の既存のオブジェクトを提示する場合にのみ使用できます。

更新: より多くのコードが追加されました!

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

1 に答える 1