MergePublication.ValidatePublication Method

Marks all subscriptions for validation during the next synchronization.

命名空间: Microsoft.SqlServer.Replication
程序集: Microsoft.SqlServer.Rmo (in microsoft.sqlserver.rmo.dll)

语法

声明
Public Sub ValidatePublication ( _
    validationOption As ValidationOption _
)
public void ValidatePublication (
    ValidationOption validationOption
)
public:
void ValidatePublication (
    ValidationOption validationOption
)
public void ValidatePublication (
    ValidationOption validationOption
)
public function ValidatePublication (
    validationOption : ValidationOption
)

参数

  • validationOption
    A ValidationOption value that specifies the validation options.

备注

The result of the validation operation is written to the agent history, which is viewed using Replication Monitor.

Calling ValidatePublication is equivalent to executing sp_validatemergepublication.

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.

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

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

示例

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

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

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

线程安全

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 的硬件和软件要求。

请参阅

参考

MergePublication Class
MergePublication Members
Microsoft.SqlServer.Replication Namespace

其他资源

How to: Validate Data at the Subscriber (RMO Programming)
验证已复制的数据