次の方法で共有


サブスクリプションのセキュリティ設定を表示および変更する方法 (RMO プログラミング)

レプリケーションに必要なセキュリティ アカウント設定 (ログインとパスワード) は、パブリケーションおよびサブスクリプションの作成時に定義されます。これらの設定は、レプリケーション管理オブジェクト (RMO) を使用して後から変更することもできます。使用する RMO のクラスとプロパティは、エージェントの種類およびサーバー接続の種類によって異なります。

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

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

レプリケーション サーバーに格納されているパスワードのインスタンスをすべて変更するには

  1. ServerConnection クラスを使用して、レプリケーション サーバーに対する接続を作成します。

  2. 手順 1. で作成した接続を使用して、ReplicationServer クラスのインスタンスを作成します。

  3. ChangeReplicationServerPasswords メソッドを呼び出します。次のパラメータを指定します。

    • security_mode - ReplicationSecurityMode 値。パスワードのすべてのインスタンスを変更するために使用する認証の種類を指定します。

    • login - パスワードのすべてのインスタンスを変更するために使用するログイン。

    • password - 新しいパスワード値。

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

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

      注意

      固定サーバー ロール sysadmin のメンバ以外、このメソッドを呼び出すことはできません。

  4. パスワードを更新する必要のある、レプリケーション トポロジ内のすべてのサーバーについて、手順 1. から手順 3. を繰り返します。

ディストリビューション エージェントのセキュリティ設定をプッシュ サブスクリプション用からトランザクション パブリケーション用に変更するには

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

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

  3. サブスクリプションの PublicationNameDatabaseNameSubscriberNameSubscriptionDBName の各プロパティを設定し、ConnectionContext プロパティに対し、手順 1. で作成した接続を設定します。

  4. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したサブスクリプションのプロパティが正しく定義されていないか、サブスクリプションが存在していません。

  5. TransSubscription のインスタンスに対し、次のいずれかまたは複数のセキュリティ プロパティを設定します。

    • エージェントの実行に使用する Windows アカウントの資格情報を変更するには、SynchronizationAgentProcessSecurityLogin フィールドおよび Password フィールドを設定します。

    • エージェントがサブスクライバとの接続に使用する認証の種類に Windows 統合認証を指定するには、SubscriberSecurity プロパティの WindowsAuthentication フィールドを true に設定します。

    • エージェントがサブスクライバとの接続に使用する認証の種類に SQL Server 認証を指定するには、SubscriberSecurity プロパティの WindowsAuthentication フィールドを false に設定し、さらに、SqlStandardLogin フィールドおよび SqlStandardPassword フィールドに対して、サブスクライバのログイン資格情報を設定します。

      注意

      ディストリビュータに対するエージェント接続は、常に、SynchronizationAgentProcessSecurity によって指定された Windows 資格情報を使用して確立されます。このアカウントは、Windows 認証を使ってリモート接続を確立する際にも使用されます。

  6. (省略可) CachePropertyChanges に true を指定した場合、CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。CachePropertyChanges に false (既定値) を指定した場合、変更は直ちにサーバーに送られます。

ディストリビューション エージェントのセキュリティ設定をプル サブスクリプション用からトランザクション パブリケーション用に変更するには

  1. ServerConnection クラスを使用して、サブスクライバへの接続を作成します。

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

  3. サブスクリプションの PublicationNameDatabaseNamePublisherNamePublicationDBName の各プロパティを設定し、ConnectionContext プロパティに対し、手順 1. で作成した接続を設定します。

  4. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したサブスクリプションのプロパティが正しく定義されていないか、サブスクリプションが存在していません。

  5. TransPullSubscription のインスタンスに対し、次のいずれかまたは複数のセキュリティ プロパティを設定します。

    • エージェントの実行に使用する Windows アカウントの資格情報を変更するには、SynchronizationAgentProcessSecurityLogin フィールドおよび Password フィールドを設定します。

    • エージェントがディストリビュータとの接続に使用する認証の種類に Windows 統合認証を指定するには、DistributorSecurity プロパティの WindowsAuthentication フィールドを true に設定します。

    • エージェントがディストリビュータとの接続に使用する認証の種類に SQL Server 認証を指定するには、DistributorSecurity プロパティの WindowsAuthentication フィールドを false に設定し、さらに、SqlStandardLogin フィールドおよび SqlStandardPassword フィールドに対して、ディストリビュータのログイン資格情報を設定します。

      注意

      サブスクライバに対するエージェント接続は、常に、SynchronizationAgentProcessSecurity によって指定された Windows 資格情報を使用して確立されます。このアカウントは、Windows 認証を使ってリモート接続を確立する際にも使用されます。

  6. (省略可) CachePropertyChanges に true を指定した場合、CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。CachePropertyChanges に false (既定値) を指定した場合、変更は直ちにサーバーに送られます。

マージ エージェントのセキュリティ設定をプル サブスクリプション用からマージ パブリケーション用に変更するには

  1. ServerConnection クラスを使用して、サブスクライバへの接続を作成します。

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

  3. サブスクリプションの PublicationNameDatabaseNamePublisherNamePublicationDBName の各プロパティを設定し、ConnectionContext プロパティに対し、手順 1. で作成した接続を設定します。

  4. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したサブスクリプションのプロパティが正しく定義されていないか、サブスクリプションが存在していません。

  5. MergePullSubscription のインスタンスに対し、次のいずれかまたは複数のセキュリティ プロパティを設定します。

    • エージェントの実行に使用する Windows アカウントの資格情報を変更するには、SynchronizationAgentProcessSecurityLogin フィールドおよび Password フィールドを設定します。

    • エージェントがディストリビュータとの接続に使用する認証の種類に Windows 統合認証を指定するには、DistributorSecurity プロパティの WindowsAuthentication フィールドを true に設定します。

    • エージェントがディストリビュータとの接続に使用する認証の種類に SQL Server 認証を指定するには、DistributorSecurity プロパティの WindowsAuthentication フィールドを false に設定し、さらに、SqlStandardLogin フィールドおよび SqlStandardPassword フィールドに対して、ディストリビュータのログイン資格情報を設定します。

    • エージェントがパブリッシャとの接続に使用する認証の種類に Windows 統合認証を指定するには、PublisherSecurity プロパティの WindowsAuthentication フィールドを true に設定します。

    • エージェントがパブリッシャとの接続に使用する認証の種類に SQL Server 認証を指定するには、PublisherSecurity プロパティの WindowsAuthentication フィールドを false に設定し、さらに、SqlStandardLogin フィールドおよび SqlStandardPassword フィールドに対して、パブリッシャのログイン資格情報を設定します。

      注意

      サブスクライバに対するエージェント接続は、常に、SynchronizationAgentProcessSecurity によって指定された Windows 資格情報を使用して確立されます。このアカウントは、Windows 認証を使ってリモート接続を確立する際にも使用されます。

  6. (省略可) CachePropertyChanges に true を指定した場合、CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。CachePropertyChanges に false (既定値) を指定した場合、変更は直ちにサーバーに送られます。

マージ エージェントのセキュリティ設定をプッシュ サブスクリプション用からマージ パブリケーション用に変更するには

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

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

  3. サブスクリプションの PublicationNameDatabaseNameSubscriberNameSubscriptionDBName の各プロパティを設定し、ConnectionContext プロパティに対し、手順 1. で作成した接続を設定します。

  4. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したサブスクリプションのプロパティが正しく定義されていないか、サブスクリプションが存在していません。

  5. MergeSubscription のインスタンスに対し、次のいずれかまたは複数のセキュリティ プロパティを設定します。

    • エージェントの実行に使用する Windows アカウントの資格情報を変更するには、SynchronizationAgentProcessSecurityLogin フィールドおよび Password フィールドを設定します。

    • エージェントがサブスクライバとの接続に使用する認証の種類に Windows 統合認証を指定するには、SubscriberSecurity プロパティの WindowsAuthentication フィールドを true に設定します。

    • エージェントがサブスクライバとの接続に使用する認証の種類に SQL Server 認証を指定するには、SubscriberSecurity プロパティの WindowsAuthentication フィールドを false に設定し、さらに、SqlStandardLogin フィールドおよび SqlStandardPassword フィールドに対して、サブスクライバのログイン資格情報を設定します。

    • エージェントがパブリッシャとの接続に使用する認証の種類に Windows 統合認証を指定するには、PublisherSecurity プロパティの WindowsAuthentication フィールドを true に設定します。

    • エージェントがパブリッシャとの接続に使用する認証の種類に SQL Server 認証を指定するには、PublisherSecurity プロパティの WindowsAuthentication フィールドを false に設定し、さらに、SqlStandardLogin フィールドおよび SqlStandardPassword フィールドに対して、パブリッシャのログイン資格情報を設定します。

      注意

      ディストリビュータに対するエージェント接続は、常に、SynchronizationAgentProcessSecurity によって指定された Windows 資格情報を使用して確立されます。このアカウントは、Windows 認証を使ってリモート接続を確立する際にも使用されます。

  6. (省略可) CachePropertyChanges に true を指定した場合、CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。CachePropertyChanges に false (既定値) を指定した場合、変更は直ちにサーバーに送られます。

即時更新サブスクライバがトランザクション パブリッシャへの接続時に使用するログイン情報を変更するには

  1. ServerConnection クラスを使用して、サブスクライバへの接続を作成します。

  2. サブスクリプション データベースの ReplicationDatabase クラスのインスタンスを作成します。Name を指定し、ConnectionContext に手順 1. の ServerConnection を指定します。

  3. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 2. で指定したデータベースのプロパティが正しく定義されていないか、サブスクリプション データベースが存在していません。

  4. LinkPublicationForUpdateableSubscription メソッドに次のパラメータを指定して呼び出します。

    • Publisher - パブリッシャの名前。

    • PublisherDB - パブリケーション データベースの名前。

    • Publication - 即時更新サブスクライバでサブスクライブしているパブリケーションの名前。

    • Distributor - ディストリビュータの名前。

    • PublisherSecurity - PublisherConnectionSecurityContext オブジェクト。即時更新サブスクライバがパブリッシャに接続するときのセキュリティ モードと、その接続に必要なログイン資格情報を指定します。

使用例

次の例では、指定されたログイン値をチェックし、該当する Windows ログイン、または、サーバー上のレプリケーションによって格納された SQL Server ログインを対象にすべてのパスワードを変更します。

           // Set the Distributor and distribution database names.
            string serverName = publisherInstance;

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

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

                server = new ReplicationServer(conn);

                // Load server properties, if it exists.
                if (server.LoadProperties())
                {
                    string[] slash = new string[1];
                    slash[1] = @"\";

                    // If the login is in the form string\string, assume we are 
                    // changing the password for a Windows login.
                    if (login.Split(slash, StringSplitOptions.None).Length == 2)
                    {
                        //Change the password for the all connections that use
                        // the Windows login. 
                        server.ChangeReplicationServerPasswords(
                                ReplicationSecurityMode.Integrated, login, password);
                    }
                    else
                    {
                        // Change the password for the all connections that use
                        // the SQL Server login. 
                        server.ChangeReplicationServerPasswords(
                                ReplicationSecurityMode.SqlStandard, login, password);
                    }
                }
                else
                {
                    throw new ApplicationException(String.Format(
                        "Properties for {0} could not be retrieved.", publisherInstance));
                }
            }
            catch (Exception ex)
            {
                // Implement the appropriate error handling here. 
                throw new ApplicationException(String.Format(
                    "An error occured when changing agent login " +
                    " credentials on {0}.",serverName), ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Set the Distributor and distribution database names.
Dim serverName As String = publisherInstance

Dim server As ReplicationServer

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

Try
    ' Open the connection. 
    conn.Connect()

    server = New ReplicationServer(conn)

    ' Load server properties, if it exists.
    If server.LoadProperties() Then

        ' If the login is in the form string\string, assume we are 
        ' changing the password for a Windows login.
        If login.Split("\").Length = 2 Then

            ' Change the password for the all connections that use
            ' the Windows login. 
            server.ChangeReplicationServerPasswords( _
            ReplicationSecurityMode.Integrated, login, password)
        Else

            ' Change the password for the all connections that use
            ' the SQL Server login. 
            server.ChangeReplicationServerPasswords( _
            ReplicationSecurityMode.SqlStandard, login, password)
        End If
    Else
        Throw New ApplicationException(String.Format( _
         "Properties for {0} could not be retrieved.", publisherInstance))
    End If
Catch ex As Exception
    ' Implement the appropriate error handling here. 
    Throw New ApplicationException(String.Format( _
     "An error occured when changing agent login " + _
     " credentials on {0}.", serverName), ex)
Finally
    conn.Disconnect()
End Try