MergeSynchronizationAgent クラス

定義

レプリケーション マージ エージェントの機能を提供します。

public ref class MergeSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft::SqlServer::Replication::IMergeSynchronizationAgent
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComSourceInterfaces(typeof(Microsoft.SqlServer.Replication.IComStatusEvent))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.Guid("ee5ee47e-6d29-448f-b2d2-f8e632db336a")]
public class MergeSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft.SqlServer.Replication.IMergeSynchronizationAgent
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComSourceInterfaces(typeof(Microsoft.SqlServer.Replication.IComStatusEvent))>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Runtime.InteropServices.Guid("ee5ee47e-6d29-448f-b2d2-f8e632db336a")>]
type MergeSynchronizationAgent = class
    inherit MarshalByRefObject
    interface IDisposable
    interface IMergeSynchronizationAgent
Public Class MergeSynchronizationAgent
Inherits MarshalByRefObject
Implements IDisposable, IMergeSynchronizationAgent
継承
MergeSynchronizationAgent
属性
実装

次の例では、プッシュ サブスクリプションをSynchronize同期するために、プロパティからSynchronizationAgentアクセスされるクラスのMergeSynchronizationAgentインスタンスでメソッドが呼び出されます。

// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

MergeSubscription subscription;

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

    // Define the subscription.
    subscription = new MergeSubscription();
    subscription.ConnectionContext = conn;
    subscription.DatabaseName = publicationDbName;
    subscription.PublicationName = publicationName;
    subscription.SubscriptionDBName = subscriptionDbName;
    subscription.SubscriberName = subscriberName;

    // If the push subscription exists, start the synchronization.
    if (subscription.LoadProperties())
    {
        // Check that we have enough metadata to start the agent.
        if (subscription.SubscriberSecurity != null)
        {
            // Synchronously start the Merge Agent for the subscription.
            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 push subscription does not exist.
        throw new ApplicationException(String.Format(
            "The 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.", ex);
}
finally
{
    conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Dim subscription As MergeSubscription

Try
    ' Connect to the Publisher
    conn.Connect()

    ' Define the subscription.
    subscription = New MergeSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = publicationDbName
    subscription.PublicationName = publicationName
    subscription.SubscriptionDBName = subscriptionDbName
    subscription.SubscriberName = subscriberName

    ' If the push subscription exists, start the synchronization.
    If subscription.LoadProperties() Then
        ' Check that we have enough metadata to start the agent.
        If Not subscription.SubscriberSecurity Is Nothing Then
            ' Synchronously start the Merge Agent for the subscription.
            ' Log agent messages to an output file.
            subscription.SynchronizationAgent.Output = "mergeagent.log"
            subscription.SynchronizationAgent.OutputVerboseLevel = 2
            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.")
        End If
    Else
        ' Do something here if the push subscription does not exist.
        Throw New ApplicationException(String.Format( _
         "The subscription to '{0}' does not exist on {1}", _
         publicationName, subscriberName))
    End If
Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
    conn.Disconnect()
End Try

次の例では、マージ サブスクリプションの同期をとるために MergeSynchronizationAgent クラスのインスタンスを使用しています。 CreateSyncAgentByDefault の値を false にしてプル サブスクリプションが作成されているため、追加のプロパティを指定する必要があります。

// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string distributorName = distributorInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
string hostname = @"adventure-works\garrett1";
string webSyncUrl = "https://" + publisherInstance + "/SalesOrders/replisapi.dll";

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

MergePullSubscription subscription;
MergeSynchronizationAgent agent;

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

    // Define the pull subscription.
    subscription = new MergePullSubscription();
    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;

        // Check that we have enough metadata to start the agent.
        if (agent.PublisherSecurityMode == null)
        {
            // Set the required properties that could not be returned
            // from the MSsubscription_properties table. 
            agent.PublisherSecurityMode = SecurityMode.Integrated;
            agent.DistributorSecurityMode = SecurityMode.Integrated;
            agent.Distributor = publisherName;
            agent.HostName = hostname;

            // Set optional Web synchronization properties.
            agent.UseWebSynchronization = true;
            agent.InternetUrl = webSyncUrl;
            agent.InternetSecurityMode = SecurityMode.Standard;
            agent.InternetLogin = winLogin;
            agent.InternetPassword = winPassword;
        }
        // Enable agent output to the console.
        agent.OutputVerboseLevel = 1;
        agent.Output = "";

        // Synchronously start the Merge Agent for the subscription.
        agent.Synchronize();
    }
    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();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
Dim hostname As String = "adventure-works\garrett1"
Dim webSyncUrl As String = "https://" + publisherInstance + "/SalesOrders/replisapi.dll"

' Create a connection to the Subscriber.
Dim conn As ServerConnection = New ServerConnection(subscriberName)

Dim subscription As MergePullSubscription
Dim agent As MergeSynchronizationAgent

Try
    ' Connect to the Subscriber.
    conn.Connect()

    ' Define the pull subscription.
    subscription = New MergePullSubscription()
    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() Then
        ' Get the agent for the subscription.
        agent = subscription.SynchronizationAgent

        ' Check that we have enough metadata to start the agent.
        If agent.PublisherSecurityMode = Nothing Then
            ' Set the required properties that could not be returned
            ' from the MSsubscription_properties table. 
            agent.PublisherSecurityMode = SecurityMode.Integrated
            agent.Distributor = publisherInstance
            agent.DistributorSecurityMode = SecurityMode.Integrated
            agent.HostName = hostname

            ' Set optional Web synchronization properties.
            agent.UseWebSynchronization = True
            agent.InternetUrl = webSyncUrl
            agent.InternetSecurityMode = SecurityMode.Standard
            agent.InternetLogin = winLogin
            agent.InternetPassword = winPassword
        End If

        ' Enable agent logging to the console.
        agent.OutputVerboseLevel = 1
        agent.Output = ""

        ' Synchronously start the Merge Agent for the subscription.
        agent.Synchronize()
    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))
    End If
Catch ex As Exception
    ' 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()
End Try

注釈

MergeSynchronizationAgent クラスでは、次のレプリケーション タスクを実行するための機能がサポートされています。

  • サブスクリプションの同期をとります。

  • 同期中にアップロード フェーズのみを実行するか、ダウンロード フェーズのみを実行するか、それとも両方のフェーズを実行するかを指定します。

  • 必要なデータがサブスクリプションにあることを検証します。

  • サブスクリプションの初期スナップショットを適用するときに使用できる別のスナップショット フォルダーを指定します。

コンストラクター

MergeSynchronizationAgent()

MergeSynchronizationAgent クラスのインスタンスを作成します。

プロパティ

AlternateSynchronizationPartnerCollection

サブスクリプションの代替同期パートナーを取得します。

AltSnapshotFolder

サブスクリプションの代替スナップショット フォルダーを取得します。値の設定も可能です。

ComErrorCollection

レプリケーション エージェントで発生したエラーのコレクションを取得します。

Distributor

サブスクリプションのディストリビューターとして動作している Microsoft SQL Server のインスタンスの名前を取得します。値の設定も可能です。

DistributorAddress

プロパティが指定されたときにディストリビューターに接続するために使用されるネットワーク アドレスを DistributorNetwork 取得または設定します。

DistributorEncryptedPassword

ディストリビューターで暗号化されたパスワードを取得または設定します。

DistributorLogin

SQL Server認証を使用してディストリビューターに接続するときに使用するログイン名を取得または設定します。

DistributorNetwork

ディストリビューターに接続するときに使用されるクライアントの Net-Library を取得します。値の設定も可能です。

DistributorPassword

SQL Server認証を使用してディストリビューターに接続するときに使用するパスワードを設定します。

DistributorSecurityMode

ディストリビューターへの接続時に使用するセキュリティ モードを取得または設定します。

DownloadGenerationsPerBatch

パブリッシャーからサブスクライバーに変更をダウンロードする間に、1 つのバッチで処理される生成結果の数を取得します。値の設定も可能です。 生成結果は、アーティクルごとに変更の論理グループとして定義されます。

DynamicSnapshotLocation

このサブスクライバーのパーティション スナップショットの場所を取得します。値の設定も可能です。

ExchangeType

同期中のデータ交換の方法を取得します。値の設定も可能です。

FileTransferType

初期スナップショット ファイルをサブスクライバーに転送する方法を取得します。値の設定も可能です。

HostName

HOST_NAME関数を使用するパラメーター化フィルターを評価するときにマージ エージェントで使用される値を取得または設定します。

InputMessageFile

入力メッセージ ファイルを取得します。値の設定も可能です。

InternetLogin

Web 同期でインターネット認証を使用してパブリッシャーに接続するときに使用されるログイン名を取得します。値の設定も可能です。

InternetPassword

Web 同期でインターネット認証を使用してパブリッシャーに接続するときに使用される InternetLogin プロパティのパスワードを設定します。

InternetProxyLogin

Web 同期でインターネット プロキシ サーバーを使用して Web サーバーに接続するときに使用されるログイン名を取得します。値の設定も可能です。

InternetProxyPassword

Web 同期でインターネット プロキシ サーバーを使用して Web サーバーに接続するときに使用されるログイン名を設定します。

InternetProxyServer

Web 同期で Web サーバーに接続するときに使用されるインターネット プロキシ サーバーの名前を取得します。値の設定も可能です。

InternetSecurityMode

Web 同期で Web サーバーに接続するときに使用される HTTP 認証方法を取得します。値の設定も可能です。

InternetTimeout

Web サーバーに接続するときの HTTP タイムアウトを取得します。値の設定も可能です。

InternetUrl

Web 同期用に構成された Web サービスの URL を取得します。値の設定も可能です。

LastUpdatedTime

レプリケーション エージェントが最後にサブスクリプションの同期をとったときのタイムスタンプを取得します。

LoginTimeout

接続が確立されるまで待機する最大秒数を取得します。値の設定も可能です。

MetadataRetentionCleanup

メタデータをクリーンアップするかどうかを取得します。値の設定も可能です。

Output

エージェントの出力ファイルを返します。値の設定も可能です。

OutputMessageFile

入力メッセージ ファイルを取得します。値の設定も可能です。

OutputVerboseLevel

エージェント出力ファイルに書き込まれる情報の詳細レベルを取得または設定します。

ProfileName

エージェントが使用するプロファイルの名前を取得します。値の設定も可能です。

Publication

パブリケーションの名前を取得します。値の設定も可能です。

Publisher

サブスクリプションのパブリッシャーとして動作している Microsoft SQL Server のインスタンスの名前を取得します。値の設定も可能です。

PublisherAddress

PublisherNetwork プロパティが指定されている場合にパブリッシャーへの接続に使用されるネットワーク アドレスを取得します。値の設定も可能です。

PublisherChanges

前回の同期の間にサブスクライバーで適用されたパブリッシャーの変更の合計数を取得します。

PublisherConflicts

前回の同期の間にパブリッシャーで発生した競合の合計数を取得します。

PublisherDatabase

パブリケーション データベースの名前を取得します。値の設定も可能です。

PublisherEncryptedPassword

パブリッシャーの暗号化パスワードを取得します。値の設定も可能です。

PublisherFailoverPartner

パブリケーション データベースとのデータベース ミラーリング セッションに参加しているSQL Serverのフェールオーバー パートナー インスタンスを取得または設定します。

PublisherLogin

SQL Server認証を使用してパブリッシャーに接続するときに使用するログイン名を取得または設定します。

PublisherNetwork

パブリッシャーに接続するときに使用されるクライアントの Net-Library を取得します。値の設定も可能です。

PublisherPassword

SQL Server認証を使用してパブリッシャーに接続するときに使用するパスワードを設定します。

PublisherSecurityMode

パブリッシャーに接続するときに使用されるセキュリティ モードを取得します。値の設定も可能です。

QueryTimeout

内部クエリがタイムアウトになるまでの秒数を取得します。値の設定も可能です。

SecureDistributorEncryptedPassword

セキュリティで保護されたディストリビューターで暗号化されたパスワードを取得または設定します。

SecurePublisherEncryptedPassword

パブリッシャーの、セキュリティで保護された暗号化パスワードを取得します。値の設定も可能です。

SecureSubscriberEncryptedPassword

サブスクライバーの、セキュリティで保護された暗号化パスワードを取得します。値の設定も可能です。

Subscriber

サブスクライバーとして動作している Microsoft SQL Server のインスタンスの名前を取得します。値の設定も可能です。

SubscriberChanges

前回の同期の間にパブリッシャーで適用されたサブスクライバーの変更の合計数を取得します。

SubscriberConflicts

前回の同期の間にパブリッシャーで発生した競合の合計数を取得します。

SubscriberDatabase

サブスクリプション データベースの名前を取得します。値の設定も可能です。

SubscriberDatabasePath

サブスクライバー データベースのパスを取得します。値の設定も可能です。

SubscriberDataSourceType

サブスクライバーとして使用されるデータ ソースの種類を取得します。値の設定も可能です。

SubscriberEncryptedPassword

サブスクライバーの暗号化パスワードを取得します。値の設定も可能です。

SubscriberLogin

SQL Server認証を使用してサブスクライバーに接続するときに使用するログイン名を取得または設定します。

SubscriberPassword

SQL Server認証を使用してサブスクライバーに接続するときに使用するパスワードを設定します。

SubscriberSecurityMode

サブスクライバーに接続するときに使用されるセキュリティ モードを取得します。値の設定も可能です。

SubscriptionType

サブスクリプションがプッシュ サブスクリプションかプル サブスクリプションかを取得します。値の設定も可能です。

SyncToAlternate

同期の対象が代替同期パートナーかどうかを取得します。値の設定も可能です。

UploadGenerationsPerBatch

サブスクライバーからパブリッシャーに変更をアップロードする間に、1 つのバッチで処理される生成結果の数を取得します。値の設定も可能です。 生成結果は、アーティクルごとに変更の論理グループとして定義されます。

UseInteractiveResolver

調整時に対話型の競合回避モジュールを使用するかどうかを取得します。値の設定も可能です。

UseWebSynchronization

Web 同期が使用されるかどうかを取得します。値の設定も可能です。

Validate

同期の最後にサブスクライバー データのデータを検証するかどうかを取得します。値の設定も可能です。

WorkingDirectory

FTP を使用する場合にスナップショット ファイルにアクセスできる作業ディレクトリを取得します。値の設定も可能です。

メソッド

Abort()

同期を停止します。

ClearAllTraceFlags()

同期エージェントで使用されたすべてのトレース フラグをクリアします。

ClearTraceFlag(Int32)

トレース フラグをクリアします。

Dispose()

MergeSynchronizationAgent によって使用されているアンマネージ リソースを解放します。

Dispose(Boolean)

クラスで使用されるアンマネージ リソースを MergeSynchronizationAgent 解放し、必要に応じてマネージド リソースを解放します。

EnableTraceFlag(Int32)

フラグのトレースを有効にします。

Finalize()

エージェントを終了します。

IsSnapshotRequired()

パブリッシャーまたはディストリビューターとサブスクライバーに接続して、エージェントの次回の同期の際に新しいスナップショットが適用されるかどうかを示します。

ProcessMessagesAtPublisher()

発行元でメッセージを処理します。

ProcessMessagesAtSubscriber()

サブスクライバー側のメッセージを処理します。

Synchronize()

マージ エージェントを開始してサブスクリプションを同期します。

イベント

ComStatus

マージ エージェントが同期の Com 状態情報を返すと発生します。

Status

マージ エージェントが同期の状態情報を返すと発生します。

適用対象

スレッド セーフ

この型の public static (Visual Basic では Shared) のメンバーはすべて、スレッド セーフです。 インスタンス メンバーの場合は、スレッド セーフであるとは限りません。