Share via


방법: 구독 보안 설정 확인 및 수정(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. 구독에 대한 PublicationName, DatabaseName, SubscriberNameSubscriptionDBName 속성을 설정하고, 1단계에서 만든 연결을 ConnectionContext 속성에 대해 설정합니다.

  4. LoadProperties 메서드를 호출하여 개체 속성을 가져옵니다. 이 메서드가 false를 반환하는 경우 3단계에서 구독 속성이 올바르게 정의되지 않았거나 구독이 없는 것입니다.

  5. TransSubscription 인스턴스의 다음 보안 속성 중 하나 이상을 설정합니다.

  6. (옵션) CachePropertyChanges에 대해 true 값을 지정했으면 CommitPropertyChanges 메서드를 호출하여 서버의 변경 내용을 커밋합니다. CachePropertyChanges에 대해 false 값을 지정했으면(기본값) 변경 내용이 즉시 서버로 전송됩니다.

트랜잭션 게시에 대한 끌어오기 구독의 배포 에이전트 보안 설정을 변경하려면

  1. ServerConnection 클래스를 사용하여 구독자 연결을 만듭니다.

  2. TransPullSubscription 클래스의 인스턴스를 만듭니다.

  3. 구독에 대한 PublicationName, DatabaseName, PublisherNamePublicationDBName 속성을 설정하고, 1단계에서 만든 연결을 ConnectionContext 속성에 대해 설정합니다.

  4. LoadProperties 메서드를 호출하여 개체 속성을 가져옵니다. 이 메서드가 false를 반환하는 경우 3단계에서 구독 속성이 올바르게 정의되지 않았거나 구독이 없습니다.

  5. TransPullSubscription 인스턴스의 다음 보안 속성 중 하나 이상을 설정합니다.

  6. (옵션) CachePropertyChanges에 대해 true 값을 지정했으면 CommitPropertyChanges 메서드를 호출하여 서버의 변경 내용을 커밋합니다. CachePropertyChanges에 대해 false 값을 지정했으면(기본값) 변경 내용이 즉시 서버로 전송됩니다.

병합 게시에 대한 끌어오기 구독의 병합 에이전트 보안 설정을 변경하려면

  1. ServerConnection 클래스를 사용하여 구독자 연결을 만듭니다.

  2. MergePullSubscription 클래스의 인스턴스를 만듭니다.

  3. 구독에 대한 PublicationName, DatabaseName, PublisherNamePublicationDBName 속성을 설정하고, 1단계에서 만든 연결을 ConnectionContext 속성에 대해 설정합니다.

  4. LoadProperties 메서드를 호출하여 개체 속성을 가져옵니다. 이 메서드가 false를 반환하는 경우 3단계에서 구독 속성이 올바르게 정의되지 않았거나 구독이 없습니다.

  5. MergePullSubscription 인스턴스의 다음 보안 속성 중 하나 이상을 설정합니다.

  6. (옵션) CachePropertyChanges에 대해 true 값을 지정했으면 CommitPropertyChanges 메서드를 호출하여 서버의 변경 내용을 커밋합니다. CachePropertyChanges에 대해 false 값을 지정했으면(기본값) 변경 내용이 즉시 서버로 전송됩니다.

병합 게시에 대한 밀어넣기 구독의 병합 에이전트 보안 설정을 변경하려면

  1. ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.

  2. MergeSubscription 클래스의 인스턴스를 만듭니다.

  3. 구독에 대한 PublicationName, DatabaseName, SubscriberNameSubscriptionDBName 속성을 설정하고, 1단계에서 만든 연결을 ConnectionContext 속성에 대해 설정합니다.

  4. LoadProperties 메서드를 호출하여 개체 속성을 가져옵니다. 이 메서드가 false를 반환하는 경우 3단계에서 구독 속성이 올바르게 정의되지 않았거나 구독이 없습니다.

  5. MergeSubscription 인스턴스의 다음 보안 속성 중 하나 이상을 설정합니다.

  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 개체

이 예에서는 제공된 로그인 값을 확인하고 서버에서 복제로 저장된 SQL Server 로그인 또는 제공된 Windows 로그인의 모든 암호를 변경합니다.

         // 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