次の方法で共有


MergeSubscription クラス

パブリッシャーにおいて登録されたマージ パブリケーションに対するサブスクリプションを表します。

継承階層

System.Object
  Microsoft.SqlServer.Replication.ReplicationObject
    Microsoft.SqlServer.Replication.Subscription
      Microsoft.SqlServer.Replication.MergeSubscription

名前空間:  Microsoft.SqlServer.Replication
アセンブリ:  Microsoft.SqlServer.Rmo (Microsoft.SqlServer.Rmo.dll)

構文

'宣言
Public NotInheritable Class MergeSubscription _
    Inherits Subscription
'使用
Dim instance As MergeSubscription
public sealed class MergeSubscription : Subscription
public ref class MergeSubscription sealed : public Subscription
[<SealedAttribute>]
type MergeSubscription =  
    class 
        inherit Subscription 
    end
public final class MergeSubscription extends Subscription

MergeSubscription 型は、以下のメンバーを公開しています。

コンストラクター

  名前 説明
パブリック メソッド MergeSubscription() MergeSubscription クラスの新しいインスタンスを作成します。
パブリック メソッド MergeSubscription(String, String, String, String, ServerConnection) 指定したパブリッシャーへの接続、およびサブスクリプションを一意に定義するプロパティを使用して、MergeSubscription クラスの新しいインスタンスを作成します。

先頭に戻る

プロパティ

  名前 説明
パブリック プロパティ AgentJobId サブスクリプションの同期に使用されるエージェント ジョブの ID を取得します。 (Subscription から継承されています。)
パブリック プロパティ AgentOffload エージェント ジョブの作成時と異なるコンピューター上で同期エージェントを実行するかどうかを取得します。値の設定も可能です。このプロパティは、Microsoft SQL Server 2005 以降を実行しているディストリビューターではサポートされなくなりました。 (Subscription から継承されています。)
パブリック プロパティ AgentOffloadServer リモート エージェントのアクティブ化を使用するとき、エージェントが実行されるリモート コンピューターの名前を取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ AgentSchedule サブスクリプションの同期に使用されるエージェント ジョブのスケジュールを取得します。 (Subscription から継承されています。)
パブリック プロパティ CachePropertyChanges レプリケーション プロパティに加えられた変更をキャッシュするか、またはすぐに適用するかを取得します。値の設定も可能です。 (ReplicationObject から継承されています。)
パブリック プロパティ ConnectionContext Microsoft SQL Server のインスタンスへの接続を取得します。値の設定も可能です。 (ReplicationObject から継承されています。)
パブリック プロパティ CreateSyncAgentByDefault サブスクリプションの同期に使用されるエージェント ジョブが既定で作成されるかどうかを取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ DatabaseName パブリケーション データベースの名前を取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ Description マージ サブスクリプションの説明テキストを取得します。値の設定も可能です。
パブリック プロパティ EnabledForSynchronizationManager Microsoft Windows 同期マネージャーを使用してサブスクリプションを同期できるかどうかを指定します。 (Subscription から継承されています。)
パブリック プロパティ HostName サブスクライバーのデータ パーティションを定義するパラメーター化された行フィルターで HOST_NAME 関数が使用されている場合に、この関数に渡される値を取得します。値の設定も可能です。
パブリック プロパティ IsExistingObject サーバーにオブジェクトが存在するかどうかを取得します。 (ReplicationObject から継承されています。)
パブリック プロパティ Name 既存のサブスクリプションに割り当てられている名前を取得します。 (Subscription から継承されています。)
パブリック プロパティ Priority サーバー サブスクリプションに割り当てられた相対優先度の値を取得します。値の設定も可能です。
パブリック プロパティ PublicationName サブスクリプションがサブスクライブするパブリケーションの名前を取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ PublisherSecurity パブリッシャーに接続するためにマージ エージェントが使用するセキュリティ コンテキストを取得します。
パブリック プロパティ SqlServerName このオブジェクトの接続先となる Microsoft SQL Server インスタンスの名前を取得します。 (ReplicationObject から継承されています。)
パブリック プロパティ Status サブスクリプションの状態を取得します。 (Subscription から継承されています。)
パブリック プロパティ SubscriberName サブスクライバーとして動作している Microsoft SQL Server のインスタンスの名前を取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ SubscriberSecurity サブスクライバーへの接続に使用されるセキュリティ コンテキストを取得します。 (Subscription から継承されています。)
パブリック プロパティ SubscriberType サブスクリプションがクライアント サブスクリプションとサーバー サブスクリプションのどちらであるかを取得します。値の設定も可能です。
パブリック プロパティ SubscriptionDBName レプリケートされたデータを受信するサブスクライバーのデータベースの名前を取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ SubscriptionType プッシュ サブスクリプションまたはプル サブスクリプションに対して、サブスクリプションを登録するかどうかを取得します。 (Subscription から継承されています。)
パブリック プロパティ SynchronizationAgent サブスクリプションの同期に使用できる MergeSynchronizationAgent クラスのインスタンスを取得します。
パブリック プロパティ SynchronizationAgentName サブスクリプションの同期のために作成されるエージェント ジョブの名前を取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ SynchronizationAgentProcessSecurity Microsoft Windows アカウントを指定する場合に使用されるセキュリティ コンテキストを取得します。このアカウントに基づいて、同期エージェント ジョブが実行され、サブスクリプションが同期されます。 (Subscription から継承されています。)
パブリック プロパティ SyncType サブスクリプションを初期化する方法を取得します。値の設定も可能です。 (Subscription から継承されています。)
パブリック プロパティ UseInteractiveResolver 同期処理中にインタラクティブ競合回避モジュールを使用するかどうかを取得します。値の設定も可能です。
パブリック プロパティ UserData ユーザーが独自のデータをオブジェクトにアタッチすることを許可するオブジェクト プロパティを取得します。値の設定も可能です。 (ReplicationObject から継承されています。)

先頭に戻る

メソッド

  名前 説明
パブリック メソッド CommitPropertyChanges キャッシュされているすべてのプロパティ変更ステートメントを、Microsoft SQL Server のインスタンスに送信します。 (ReplicationObject から継承されています。)
パブリック メソッド Create パブリッシャー側でサブスクリプション登録を作成します。 (Subscription から継承されています。)
パブリック メソッド Decouple 参照先のレプリケーション オブジェクトをサーバーから切断します。 (ReplicationObject から継承されています。)
パブリック メソッド Equals (Object から継承されています。)
パブリック メソッド GetHashCode (Object から継承されています。)
パブリック メソッド GetType (Object から継承されています。)
パブリック メソッド Load サーバーから既存のオブジェクトのプロパティを読み込みます。 (ReplicationObject から継承されています。)
パブリック メソッド LoadProperties サーバーから既存のオブジェクトのプロパティを読み込みます。 (ReplicationObject から継承されています。)
パブリック メソッド Refresh オブジェクトのプロパティを再度読み込みます。 (ReplicationObject から継承されています。)
パブリック メソッド Reinitialize マージ サブスクリプションに再初期化のマークを付けます。
パブリック メソッド Remove パブリッシャーでサブスクリプション登録を削除し、プッシュ サブスクリプション用のサブスクライバーでレプリケーション オブジェクトを削除します。 (Subscription から継承されています。)
パブリック メソッド Script サブスクリプションの作成や削除に使用できる Transact-SQL スクリプトを返します。 (Subscription から継承されています。)
パブリック メソッド StopSynchronizationJob 現在サブスクリプションの同期を実行しているマージ エージェント ジョブの停止を試みます。
パブリック メソッド SynchronizeWithJob エージェント ジョブを開始してサブスクリプションを同期します。
パブリック メソッド ToString (Object から継承されています。)

先頭に戻る

説明

MergeSubscription クラスは、マージ パブリケーションに対するプル サブスクリプションとプッシュ サブスクリプションの両方で使用されます。

リモート ディストリビューターを使用するパブリッシャーを構成する場合は、SynchronizationAgentProcessSecurity を含むすべてのパラメーターに指定された値がディストリビューターにプレーン テキストとして送信されます。 Create メソッドを呼び出す前に、パブリッシャーとリモート ディストリビューター間の接続を暗号化する必要があります。 詳細については、「SQL Server への接続の暗号化」を参照してください。

スレッド セーフ

この型の public static (Microsoft Visual Basic では Shared) のすべてのメンバーは、マルチスレッド操作で安全に使用できます。 インスタンス メンバーの場合は、スレッド セーフであるとは限りません。

使用例

          // Define the Publisher, publication, and databases.
            string publicationName = "AdvWorksSalesOrdersMerge";
            string publisherName = publisherInstance;
            string subscriberName = subscriberInstance;
            string subscriptionDbName = "AdventureWorks2012Replica";
            string publicationDbName = "AdventureWorks2012";
            string hostname = @"adventure-works\garrett1";

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

            // Create the objects that we need.
            MergePublication publication;
            MergeSubscription subscription;

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

                // Ensure that the publication exists and that 
                // it supports push subscriptions.
                publication = new MergePublication();
                publication.Name = publicationName;
                publication.DatabaseName = publicationDbName;
                publication.ConnectionContext = conn;

                if (publication.IsExistingObject)
                {
                    if ((publication.Attributes & PublicationAttributes.AllowPush) == 0)
                    {
                        publication.Attributes |= PublicationAttributes.AllowPush;
                    }

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

                    // Set a schedule to synchronize the subscription every 2 hours
                    // during weekdays from 6am to 10pm.
                    subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.Weekly;
                    subscription.AgentSchedule.FrequencyInterval = Convert.ToInt32(0x003E);
                    subscription.AgentSchedule.FrequencyRecurrenceFactor = 1;
                    subscription.AgentSchedule.FrequencySubDay = ScheduleFrequencySubDay.Hour;
                    subscription.AgentSchedule.FrequencySubDayInterval = 2;
                    subscription.AgentSchedule.ActiveStartDate = 20051108;
                    subscription.AgentSchedule.ActiveEndDate = 20071231;
                    subscription.AgentSchedule.ActiveStartTime = 060000;
                    subscription.AgentSchedule.ActiveEndTime = 100000;

                    // Specify the Windows login credentials for the Merge Agent job.
                    subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
                    subscription.SynchronizationAgentProcessSecurity.Password = winPassword;

                    // Create the push subscription.
                    subscription.Create();
                }
                else
                {
                    // Do something here if the publication does not exist.
                    throw new ApplicationException(String.Format(
                        "The publication '{0}' does not exist on {1}.",
                        publicationName, publisherName));
                }
            }
            catch (Exception ex)
            {
                // Implement the appropriate error handling here.
                throw new ApplicationException(String.Format(
                    "The subscription to {0} could not be created.", publicationName), ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
Dim hostname As String = "adventure-works\garrett1"

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

' Create the objects that we need.
Dim publication As MergePublication
Dim subscription As MergeSubscription

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

    ' Ensure that the publication exists and that 
    ' it supports push subscriptions.
    publication = New MergePublication()
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName
    publication.ConnectionContext = conn

    If publication.IsExistingObject Then
        If (publication.Attributes And PublicationAttributes.AllowPush) = 0 Then
            publication.Attributes = publication.Attributes _
            Or PublicationAttributes.AllowPush
        End If

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

        ' Set a schedule to synchronize the subscription every 2 hours
        ' during weekdays from 6am to 10pm.
        subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.Weekly
        subscription.AgentSchedule.FrequencyInterval = Convert.ToInt32("0x003E", 16)
        subscription.AgentSchedule.FrequencyRecurrenceFactor = 1
        subscription.AgentSchedule.FrequencySubDay = ScheduleFrequencySubDay.Hour
        subscription.AgentSchedule.FrequencySubDayInterval = 2
        subscription.AgentSchedule.ActiveStartDate = 20051108
        subscription.AgentSchedule.ActiveEndDate = 20071231
        subscription.AgentSchedule.ActiveStartTime = 60000
        subscription.AgentSchedule.ActiveEndTime = 100000

        ' Specify the Windows login credentials for the Merge Agent job.
        subscription.SynchronizationAgentProcessSecurity.Login = winLogin
        subscription.SynchronizationAgentProcessSecurity.Password = winPassword

        ' Create the push subscription.
        subscription.Create()
    Else

        ' Do something here if the publication does not exist.
        Throw New ApplicationException(String.Format( _
         "The publication '{0}' does not exist on {1}.", _
         publicationName, publisherName))
    End If
Catch ex As Exception
    ' Implement the appropriate error handling here.
    Throw New ApplicationException(String.Format( _
    "The subscription to {0} could not be created.", publicationName), ex)
Finally
    conn.Disconnect()
End Try

スレッド セーフ

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

関連項目

参照

Microsoft.SqlServer.Replication 名前空間

MergePullSubscription

その他の技術情報

プル サブスクリプションを作成する方法 (RMO プログラミング)

プッシュ サブスクリプションを作成する方法 (RMO プログラミング)