Condividi tramite


TransPublication.ValidatePublication Metodo

Definizione

Richiama la convalida della pubblicazione inline per tutte le sottoscrizioni.

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)

Parametri

validationOption
ValidationOption

Valore dell'oggetto ValidationOption che specifica il tipo di convalida eseguito.

validationMethod
ValidationMethod

Valore dell'oggetto ValidationMethod che specifica le opzioni per la convalida del conteggio righe.

shutdownAgent
Boolean

Valore Boolean. Se true, l'agente di distribuzione viene arrestato immediatamente dopo la convalida. Se false, l'agente di distribuzione rimane in esecuzione.

Esempio

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

Commenti

Il risultato della convalida viene scritto nella cronologia dell'agente, che viene visualizzato usando Monitoraggio replica. Per altre informazioni, vedere Monitoring Replication.

Il ValidatePublication metodo può essere chiamato solo dai membri del ruolo predefinito del sysadmin server nel server di pubblicazione o dai membri del ruolo predefinito del db_owner database nel database di pubblicazione.

La chiamata ValidatePublication equivale all'esecuzione di sp_publication_validation.

Si applica a