次の方法で共有


MergeSynchronizationAgent Class

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

名前空間: Microsoft.SqlServer.Replication
アセンブリ: Microsoft.SqlServer.Replication (microsoft.sqlserver.replication.dll 内)

構文

'宣言
<GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a")> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
<ComSourceInterfacesAttribute(GetType(IComStatusEvent))> _
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Class MergeSynchronizationAgent
    Inherits MarshalByRefObject
    Implements IDisposable, IMergeSynchronizationAgent
[GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a")] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
[ComSourceInterfacesAttribute(typeof(IComStatusEvent))] 
[PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")] 
public class MergeSynchronizationAgent : MarshalByRefObject, IDisposable, IMergeSynchronizationAgent
[GuidAttribute(L"ee5ee47e-6d29-448f-b2d2-f8e632db336a")] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
[ComSourceInterfacesAttribute(typeof(IComStatusEvent))] 
[PermissionSetAttribute(SecurityAction::Demand, Name=L"FullTrust")] 
public ref class MergeSynchronizationAgent : public MarshalByRefObject, IDisposable, IMergeSynchronizationAgent
/** @attribute GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a") */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ComSourceInterfacesAttribute(Microsoft.SqlServer.Replication.IComStatusEvent) */ 
/** @attribute PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust") */ 
public class MergeSynchronizationAgent extends MarshalByRefObject implements IDisposable, IMergeSynchronizationAgent
GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a") 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
ComSourceInterfacesAttribute(Microsoft.SqlServer.Replication.IComStatusEvent) 
public class MergeSynchronizationAgent extends MarshalByRefObject implements IDisposable, IMergeSynchronizationAgent

解説

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

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

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

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

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

MergeSynchronizationAgent クラスは、SQL Server 2000 および SQL Server 2005 の両方で実行中のパブリッシャとサブスクライバで使用できます。

MergeSynchronizationAgent クラスは、SQL Server 2000 で実行中のディストリビュータでは使用できません。

継承階層

System.Object
   System.MarshalByRefObject
    Microsoft.SqlServer.Replication.MergeSynchronizationAgent

使用例

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

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

// 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 = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"

' 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 = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
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 = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
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

スレッド セーフ

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

プラットフォーム

開発プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

対象プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

参照

関連項目

MergeSynchronizationAgent Members
Microsoft.SqlServer.Replication Namespace

その他の技術情報

プル サブスクリプションを同期する方法 (RMO プログラミング)
プッシュ サブスクリプションを同期する方法 (RMO プログラミング)
レプリケーション マージ エージェント

変更履歴

リリース

履歴

2006 年 4 月 14 日

変更内容 :
  • Service Pack 1 から、MergeSynchronizationAgent オブジェクトを使用するアプリケーションでは、シングル スレッド アパートメントのスレッド モデルを使用する必要はなくなりました。スレッド セーフのセクションを変更して、この新しい動作を反映しました。