방법: 구독자에서 데이터 유효성 검사(RMO 프로그래밍)

복제를 사용하면 RMO(복제 관리 개체)를 통해 구독자의 데이터가 게시자의 데이터와 일치하는지를 프로그래밍 방식으로 확인할 수 있습니다. 사용하는 개체는 복제 토폴로지의 유형에 따라 달라집니다. 트랜잭션 복제에는 게시에 대한 모든 구독의 유효성 검사가 필요합니다.

트랜잭션 게시의 모든 아티클에 대해 데이터 유효성을 검사하려면

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

  2. TransPublication 클래스의 인스턴스를 만듭니다. 게시에 대해 NameDatabaseName 속성을 설정합니다. ConnectionContext 속성을 1단계에서 만든 연결로 설정합니다.

  3. LoadProperties 메서드를 호출하여 개체의 나머지 속성을 얻습니다. 이 메서드가 false를 반환하는 경우 2단계에서 게시 속성이 올바르게 정의되지 않았거나 해당 게시가 없는 것입니다.

  4. ValidatePublication 메서드를 호출합니다. 다음을 전달합니다.

    이렇게 하면 해당 아티클이 유효성 검사 대상으로 표시됩니다.

  5. 배포 에이전트를 아직 실행하지 않은 경우 배포 에이전트를 시작하여 각 구독을 동기화합니다. 자세한 내용은 방법: 밀어넣기 구독 동기화(RMO Programming) 또는 방법: 끌어오기 구독 동기화(RMO Programming)를 참조하십시오. 유효성 검사 작업의 결과는 에이전트 기록에 추가됩니다. 자세한 내용은 방법: 프로그래밍 방식으로 복제 모니터링(RMO 프로그래밍)을 참조하십시오.

병합 게시에 대한 모든 구독의 데이터 유효성을 검사하려면

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

  2. MergePublication 클래스의 인스턴스를 만듭니다. 게시에 대해 NameDatabaseName 속성을 설정합니다. ConnectionContext 속성을 1단계에서 만든 연결로 설정합니다.

  3. LoadProperties 메서드를 호출하여 개체의 나머지 속성을 얻습니다. 이 메서드가 false를 반환하는 경우 2단계에서 게시 속성이 올바르게 정의되지 않았거나 해당 게시가 없는 것입니다.

  4. ValidatePublication 메서드를 호출합니다. 원하는 ValidationOption을 전달합니다.

  5. 각 구독에 대해 병합 에이전트를 실행하여 유효성 검사를 시작하거나 예약된 다음 에이전트가 실행될 때까지 기다립니다. 자세한 내용은 방법: 끌어오기 구독 동기화(RMO Programming)방법: 밀어넣기 구독 동기화(RMO Programming)를 참조하십시오. 유효성 검사 작업의 결과는 에이전트 기록에 추가되며, 복제 모니터를 사용하여 해당 결과를 볼 수 있습니다. 자세한 내용은 방법: 프로그래밍 방식으로 복제 모니터링(RMO 프로그래밍)을 참조하십시오.

병합 게시에 대한 단일 구독의 데이터 유효성을 검사하려면

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

  2. MergePublication 클래스의 인스턴스를 만듭니다. 게시에 대해 NameDatabaseName 속성을 설정합니다. ConnectionContext 속성을 1단계에서 만든 연결로 설정합니다.

  3. LoadProperties 메서드를 호출하여 개체의 나머지 속성을 얻습니다. 이 메서드가 false를 반환하는 경우 2단계에서 게시 속성이 올바르게 정의되지 않았거나 해당 게시가 없는 것입니다.

  4. ValidateSubscription 메서드를 호출합니다. 구독자 이름, 유효성을 검사할 구독 데이터베이스 및 원하는 ValidationOption을 전달합니다.

  5. 유효성 검사를 시작할 구독에 대해 병합 에이전트를 실행하거나 예약된 다음 에이전트가 실행될 때까지 기다립니다. 자세한 내용은 방법: 끌어오기 구독 동기화(RMO Programming)방법: 밀어넣기 구독 동기화(RMO Programming)를 참조하십시오. 유효성 검사 작업의 결과는 에이전트 기록에 추가되며, 복제 모니터를 사용하여 해당 결과를 볼 수 있습니다. 자세한 내용은 방법: 프로그래밍 방식으로 복제 모니터링(RMO 프로그래밍)을 참조하십시오.

이 예제에서는 트랜잭션 게시에 대한 모든 구독을 대상으로 행 개수를 확인하도록 표시합니다.

         // Define the server, database, and publication names
            string publisherName = publisherInstance;
            string publicationName = "AdvWorksProductTran";
            string publicationDbName = "AdventureWorks2008R2";

            TransPublication publication;

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

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

                // Set the required properties for the publication.
                publication = new TransPublication();
                publication.ConnectionContext = conn;
                publication.Name = publicationName;
                publication.DatabaseName = publicationDbName;

                // If we can't get the properties for this publication, 
                // throw an application exception.
                if (publication.LoadProperties())
                {
                    // Initiate validataion for all subscriptions to this publication.
                    publication.ValidatePublication(ValidationOption.RowCountOnly,
                        ValidationMethod.ConditionalFast, false);

                    // If not already running, start the Distribution Agent at each 
                    // Subscriber to synchronize and validate the subscriptions.
                }
                else
                {
                    throw new ApplicationException(String.Format(
                        "Settings could not be retrieved for the publication. " +
                        "Ensure that the publication {0} exists on {1}.",
                        publicationName, publisherName));
                }
            }
            catch (Exception ex)
            {
                // Do error handling here.
                throw new ApplicationException(
                    "Subscription validation could not be initiated.", ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2008R2"

Dim publication As TransPublication

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

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

    ' Set the required properties for the publication.
    publication = New TransPublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' If we can't get the properties for this publication, 
    ' throw an application exception.
    If publication.LoadProperties() Then

        ' Initiate validataion for all subscriptions to this publication.
        publication.ValidatePublication(ValidationOption.RowCountOnly, _
         ValidationMethod.ConditionalFast, False)

        ' If not already running, start the Distribution Agent at each 
        ' Subscriber to synchronize and validate the subscriptions.
    Else
        Throw New ApplicationException(String.Format( _
         "Settings could not be retrieved for the publication. " + _
         "Ensure that the publication {0} exists on {1}.", _
         publicationName, publisherName))
    End If
Catch ex As Exception
    ' Do error handling here.
    Throw New ApplicationException( _
     "Subscription validation could not be initiated.", ex)
Finally
    conn.Disconnect()
End Try

이 예제에서는 병합 게시에 대한 특정 구독을 대상으로 행 개수를 확인하도록 표시합니다.

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

            MergePublication publication;

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

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

                // Set the required properties for the publication.
                publication = new MergePublication();
                publication.ConnectionContext = conn;
                publication.Name = publicationName;
                publication.DatabaseName = publicationDbName;


                // If we can't get the properties for this merge publication, then throw an application exception.
                if (publication.LoadProperties())
                {
                    // Initiate validation of the specified subscription.
                    publication.ValidateSubscription(subscriberName,
                        subscriptionDbName, ValidationOption.RowCountOnly);
                    
                    // Start the Merge Agent to synchronize and validate the subscription.
                }
                else
                {
                    throw new ApplicationException(String.Format(
                        "Settings could not be retrieved for the publication. " +
                        "Ensure that the publication {0} exists on {1}.",
                        publicationName, publisherName));
                }
            }
            catch (Exception ex)
            {
                // Do error handling here.
                throw new ApplicationException(String.Format(
                    "The subscription at {0} to the {1} publication could not " +
                    "be validated.", subscriberName, publicationName), ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2008R2"
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2008R2Replica"

Dim publication As MergePublication

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

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

    ' Set the required properties for the publication.
    publication = New MergePublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' If we can't get the properties for this merge publication, then throw an application exception.
    If publication.LoadProperties() Then
        ' Initiate validation of the specified subscription.
        publication.ValidateSubscription(subscriberName, _
         subscriptionDbName, ValidationOption.RowCountOnly)

        ' Start the Merge Agent to synchronize and validate the subscription.
    Else
        Throw New ApplicationException(String.Format( _
         "Settings could not be retrieved for the publication. " + _
         "Ensure that the publication {0} exists on {1}.", _
         publicationName, publisherName))
    End If
Catch ex As Exception
    ' Do error handling here.
    Throw New ApplicationException(String.Format( _
     "The subscription at {0} to the {1} publication could not " + _
     "be validated.", subscriberName, publicationName), ex)
Finally
    conn.Disconnect()
End Try