다음을 통해 공유


MergePublication.ValidatePublication(ValidationOption) 메서드

정의

모든 구독에 대해 다음 동기화 중에 유효성을 검사하도록 표시합니다.

public:
 void ValidatePublication(Microsoft::SqlServer::Replication::ValidationOption validationOption);
public void ValidatePublication (Microsoft.SqlServer.Replication.ValidationOption validationOption);
member this.ValidatePublication : Microsoft.SqlServer.Replication.ValidationOption -> unit
Public Sub ValidatePublication (validationOption As ValidationOption)

매개 변수

validationOption
ValidationOption

유효성 검사 옵션입니다.

예제

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

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 = "AdventureWorks2012"
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"

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

설명

유효성 검사 작업의 결과는 복제 모니터를 사용하여 표시되는 에이전트 기록에 기록됩니다.

호출 ValidatePublicationsp_validatemergepublication 실행하는 것과 같습니다.

메서드는 ValidatePublication 게시자에서 sysadmin 고정 서버 역할의 멤버 또는 게시 데이터베이스에서 db_owner 고정 데이터베이스 역할의 멤버만 호출할 수 있습니다.

적용 대상

추가 정보