共用方式為


TransPublication.ValidatePublication Method

Invokes inline publication validation for all subscriptions.

命名空間: Microsoft.SqlServer.Replication
組件: Microsoft.SqlServer.Rmo (in microsoft.sqlserver.rmo.dll)

語法

'宣告
Public Sub ValidatePublication ( _
    validationOption As ValidationOption, _
    validationMethod As ValidationMethod, _
    shutdownAgent As Boolean _
)
public void ValidatePublication (
    ValidationOption validationOption,
    ValidationMethod validationMethod,
    bool shutdownAgent
)
public:
void ValidatePublication (
    ValidationOption validationOption, 
    ValidationMethod validationMethod, 
    bool shutdownAgent
)
public void ValidatePublication (
    ValidationOption validationOption, 
    ValidationMethod validationMethod, 
    boolean shutdownAgent
)
public function ValidatePublication (
    validationOption : ValidationOption, 
    validationMethod : ValidationMethod, 
    shutdownAgent : boolean
)

參數

  • validationOption
    A ValidationOption object value that specifies the type of validation being performed.
  • validationMethod
    A ValidationMethod object value that specifies options for rowcount validation.
  • shutdownAgent
    A Boolean value. If true, the Distribution Agent is shut down immediately after validation. If false, the Distribution Agent continues to run.

備註

The result of the validation is written to the agent history, which is viewed using Replication Monitor. For more information, see 使用複寫監視器監視複寫.

The ValidatePublication method can only be called by members of the sysadmin fixed server role at the Publisher or by members of the db_owner fixed database role on the publication database.

Calling ValidatePublication is equivalent to executing sp_publication_validation.

The ValidatePublication method is available for instances of SQL Server 2000 and SQL Server 2005.

This namespace, class, or member is supported only in version 2.0 of the .NET Framework.

範例

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

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

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

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

平台

開發平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

目標平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

請參閱

參考

TransPublication Class
TransPublication Members
Microsoft.SqlServer.Replication Namespace