1

RMO を使用してプログラムでマージ同期を実行しようとしています。基本的に、次のように SQL Server のサンプル コードをコピーしました。

// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);

MergePullSubscription subscription;

try
{
    // Connect to the Subscriber.
    conn.Connect();

    // Define the pull subscription.
    subscription = new MergePullSubscription(subscriptionDbName, publisherName, publicationDbName,
                                             publicationName, conn, false);

    // If the pull subscription exists, then start the synchronization.
    if (subscription.LoadProperties())
    {
        // Check that we have enough metadata to start the agent.
        if (subscription.PublisherSecurity != null || subscription.DistributorSecurity != null)
        {
            subscription.SynchronizationAgent.Synchronize();
        }
        else
        {
            throw new ApplicationException("There is insufficent metadata to " +
                "synchronize the subscription. Recreate the subscription with " +
                "the agent job or supply the required agent properties at run time.");
        }
    }
    else
    {
        // Do something here if the pull subscription does not exist.
        throw new ApplicationException(String.Format(
            "A subscription to '{0}' does not exist on {1}",
            publicationName, subscriberName));
    }
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The subscription could not be " +
        "synchronized. Verify that the subscription has " +
        "been defined correctly.", ex);
}
finally
{
    conn.Disconnect();
}

サーバー マージ パブリケーションを正しく定義しましたが、上記のコードを実行すると、次の呼び出しで null 参照例外が発生します。

subscription.SynchronizationAgent.Synchronize();

スタック トレースは次のとおりです。

at Microsoft.SqlServer.Replication.MergeSynchronizationAgent.StatusEventSinkMethod(String message, Int32 percent, Int32* returnValue)

at Test.ConsoleTest.Program.SynchronizePullSubscription() in F:\Visual Studio Projects\Test\source\Test.ConsoleTest\Program.cs:line 124

スタック トレースから、Status イベントと関係があるように見えますが、ハンドラーが定義されていないため、ハンドラーを定義しても違いはありません。

4

1 に答える 1

0

なぜこれが起こっているのか、私は本当に理解していませんでした。あるマシンでは動作させることができましたが、別のマシンでは常に NullReferenceException が発生しました。

SQL Server 2005 SDK フォルダー内のアセンブリを参照していたことがわかりました。これらを削除し、代わりに SQL Server 2008 のものを参照しましたが、それ以降は正常に機能しています。

多分これは他の誰かを助けるでしょう。

于 2010-03-18T00:14:26.213 に答える