Share via


パブリッシャとディストリビュータのプロパティを表示および変更する方法 (RMO プログラミング)

パブリッシャとディストリビュータのプロパティは、レプリケーション管理オブジェクト (RMO) を使用してプログラムから表示および変更できます。

ディストリビュータのプロパティを表示および変更するには

  1. ServerConnection クラスを使用して、ディストリビュータへの接続を作成します。

  2. ReplicationServer クラスのインスタンスを作成します。手順 1. の ServerConnection を渡します。

  3. (省略可) IsDistributor プロパティをチェックして、現在接続されているサーバーがディストリビュータであることを確認します。

  4. Load メソッドを呼び出して、サーバーからプロパティを取得します。

  5. (省略可) プロパティを変更するには、ReplicationServer オブジェクトの設定可能なディストリビュータ プロパティに新しい値を設定します。

  6. (省略可) ReplicationServer オブジェクトの CachePropertyChanges プロパティが true に設定されている場合は、CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。

ディストリビューション データベースのプロパティを表示および変更するには

  1. ServerConnection クラスを使用して、ディストリビュータへの接続を作成します。

  2. DistributionDatabase クラスのインスタンスを作成します。name プロパティを指定し、手順 1. の ServerConnection オブジェクトを渡します。

  3. LoadProperties メソッドを呼び出して、サーバーからプロパティを取得します。このメソッドから false が返された場合、指定した名前のデータベースはサーバー上に存在しません。

  4. (省略可) プロパティを変更するには、DistributionDatabase の設定可能なプロパティに新しい値を設定します。

  5. (省略可) DistributionDatabase オブジェクトの CachePropertyChanges プロパティが true に設定されている場合は、CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。

パブリッシャのプロパティを表示および変更するには

  1. ServerConnection クラスを使用して、パブリッシャへの接続を作成します。

  2. DistributionPublisher クラスのインスタンスを作成します。Name プロパティを指定し、手順 1. の ServerConnection オブジェクトを渡します。

  3. (省略可) プロパティを変更するには、DistributionPublisher の設定可能なプロパティに新しい値を設定します。

  4. (省略可) DistributionPublisher オブジェクトの CachePropertyChanges プロパティが true に設定されている場合は、CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。

パブリッシャからディストリビュータへの管理接続に使用されているパスワードを変更するには

  1. ServerConnection クラスを使用して、ディストリビュータへの接続を作成します。

  2. ReplicationServer クラスのインスタンスを作成します。

  3. ConnectionContext プロパティに、手順 1. の接続を設定します。

  4. Load メソッドを呼び出して、オブジェクトのプロパティを取得します。

  5. ChangeDistributorPassword メソッドを呼び出します。新しいパスワード値を password パラメータに渡します。

    セキュリティに関する注意セキュリティに関する注意

    可能であれば、実行時にセキュリティ資格情報の入力を求めるメッセージを表示します。資格情報を保存する必要がある場合は、Microsoft Windows .NET Framework に用意されている暗号化サービスを使用します。

  6. (省略可) このディストリビュータを使用している各リモート パブリッシャでパスワードを変更するには、次の手順に従います。

    1. ServerConnection クラスを使用して、パブリッシャへの接続を作成します。

    2. ReplicationServer クラスのインスタンスを作成します。

    3. ConnectionContext プロパティに、手順 6a. で作成した接続を設定します。

    4. Load メソッドを呼び出して、オブジェクトのプロパティを取得します。

    5. ChangeDistributorPassword メソッドを呼び出します。手順 5. の新しいパスワード値を password パラメータに渡します。

使用例

次の例に、ディストリビューションのプロパティおよびディストリビューション データベースのプロパティを変更する方法を示します。

セキュリティに関する注意セキュリティに関する注意

資格情報をコードに記述するのを避けるため、新しいディストリビュータ パスワードは実行時に指定するようにしています。

            // Set the Distributor and distribution database names.
            string distributionDbName = "distribution";
            string distributorName = publisherInstance;

            ReplicationServer distributor;
            DistributionDatabase distributionDb;

            // Create a connection to the Distributor using Windows Authentication.
            ServerConnection conn = new ServerConnection(distributorName);

            try
            {
                // Open the connection. 
                conn.Connect();

                distributor = new ReplicationServer(conn);

                // Load Distributor properties, if it is installed.
                if (distributor.LoadProperties())
                {
                    // Password supplied at runtime.
                    distributor.ChangeDistributorPassword(password);
                    distributor.AgentCheckupInterval = 5;

                    // Save changes to the Distributor properties.
                    distributor.CommitPropertyChanges();
                }
                else
                {
                    throw new ApplicationException(
                        String.Format("{0} is not a Distributor.", publisherInstance));
                }

                // Create an object for the distribution database 
                // using the open Distributor connection.
                distributionDb = new DistributionDatabase(distributionDbName, conn);

                // Change distribution database properties.
                if (distributionDb.LoadProperties())
                {
                    // Change maximum retention period to 48 hours and history retention 
                    // period to 24 hours.
                    distributionDb.MaxDistributionRetention = 48;
                    distributionDb.HistoryRetention = 24;

                    // Save changes to the distribution database properties.
                    distributionDb.CommitPropertyChanges();
                }
                else
                {
                    // Do something here if the distribution database does not exist.
                }
            }
            catch (Exception ex)
            {
                // Implement the appropriate error handling here. 
                throw new ApplicationException("An error occured when changing Distributor " +
                    " or distribution database properties.", ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Set the Distributor and distribution database names.
Dim distributionDbName As String = "distribution"
Dim distributorName As String = publisherInstance

Dim distributor As ReplicationServer
Dim distributionDb As DistributionDatabase

' Create a connection to the Distributor using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(distributorName)

Try
    ' Open the connection. 
    conn.Connect()

    distributor = New ReplicationServer(conn)

    ' Load Distributor properties, if it is installed.
    If distributor.LoadProperties() Then
        ' Password supplied at runtime.
        distributor.ChangeDistributorPassword(password)
        distributor.AgentCheckupInterval = 5

        ' Save changes to the Distributor properties.
        distributor.CommitPropertyChanges()
    Else
        Throw New ApplicationException( _
            String.Format("{0} is not a Distributor.", publisherInstance))
    End If

    ' Create an object for the distribution database 
    ' using the open Distributor connection.
    distributionDb = New DistributionDatabase(distributionDbName, conn)

    ' Change distribution database properties.
    If distributionDb.LoadProperties() Then
        ' Change maximum retention period to 48 hours and history retention 
        ' period to 24 hours.
        distributionDb.MaxDistributionRetention = 48
        distributionDb.HistoryRetention = 24

        ' Save changes to the distribution database properties.
        distributionDb.CommitPropertyChanges()
    Else
        ' Do something here if the distribution database does not exist.
    End If
Catch ex As Exception
    ' Implement the appropriate error handling here. 
    Throw New ApplicationException("An error occured when changing Distributor " + _
        " or distribution database properties.", ex)
Finally
    conn.Disconnect()
End Try