Compartilhar via


TransPublication.ValidatePublication Método

Definição

Invoca a validação de publicação embutida de todas as assinaturas.

public:
 void ValidatePublication(Microsoft::SqlServer::Replication::ValidationOption validationOption, Microsoft::SqlServer::Replication::ValidationMethod validationMethod, bool shutdownAgent);
public void ValidatePublication (Microsoft.SqlServer.Replication.ValidationOption validationOption, Microsoft.SqlServer.Replication.ValidationMethod validationMethod, bool shutdownAgent);
member this.ValidatePublication : Microsoft.SqlServer.Replication.ValidationOption * Microsoft.SqlServer.Replication.ValidationMethod * bool -> unit
Public Sub ValidatePublication (validationOption As ValidationOption, validationMethod As ValidationMethod, shutdownAgent As Boolean)

Parâmetros

validationOption
ValidationOption

Um valor do objeto ValidationOption que especifica o tipo de validação que está sendo executada.

validationMethod
ValidationMethod

Um valor do objeto ValidationMethod que especifica as opções para validação do número de linhas.

shutdownAgent
Boolean

Um valor Boolean. Se true, o Agente de Distribuição será desligado imediatamente depois da validação. Se false, o Agente de Distribuição continuará a ser executado.

Exemplos

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

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 = "AdventureWorks2012"

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

Comentários

O resultado da validação é gravado no histórico do agente, que é exibido usando o Replication Monitor. Para obter mais informações, consulte Monitoring Replication.

O ValidatePublication método só pode ser chamado por membros da sysadmin função de servidor fixa no Publicador ou por membros da função de banco de db_owner dados fixa no banco de dados de publicação.

A chamada ValidatePublication é equivalente à execução de sp_publication_validation.

Aplica-se a