TransPullSubscription.Reinitialize 方法

Marks the pull subscription for reinitialization.

命名空间:  Microsoft.SqlServer.Replication
程序集:  Microsoft.SqlServer.Rmo(在 Microsoft.SqlServer.Rmo.dll 中)

语法

声明
Public Sub Reinitialize
用法
Dim instance As TransPullSubscription

instance.Reinitialize()
public void Reinitialize()
public:
void Reinitialize()
member Reinitialize : unit -> unit
public function Reinitialize()

注释

After calling the Reinitialize method, you must start synchronization to reinitialize the subscription. For more information, see 如何重新初始化订阅(RMO 编程).

The Reinitialize method can only be called by members of sysadmin fixed server role at the Subscriber or by members of the db_owner fixed database role on the subscription database.

Calling Reinitialize is equivalent to executing sp_reinitpullsubscription.

示例

         // Define server, publication, and database names.
            String subscriberName = subscriberInstance;
            String publisherName = publisherInstance;
            String publicationName = "AdvWorksProductTran";
            String publicationDbName = "AdventureWorks2012";
            String subscriptionDbName = "AdventureWorks2012Replica";

            // Create a connection to the Subscriber.
            ServerConnection conn = new ServerConnection(subscriberName);

            TransPullSubscription subscription;

            try
            {
                // Connect to the Subscriber.
                conn.Connect();

                // Define subscription properties.
                subscription = new TransPullSubscription();
                subscription.ConnectionContext = conn;
                subscription.DatabaseName = subscriptionDbName;
                subscription.PublisherName = publisherName;
                subscription.PublicationDBName = publicationDbName;
                subscription.PublicationName = publicationName;

                // If the pull subscription and the job exists, mark the subscription
                // for reinitialization and start the agent job.
                if (subscription.LoadProperties() && subscription.AgentJobId != null)
                {
                    subscription.Reinitialize();
                    subscription.SynchronizeWithJob();
                }
                else
                {
                    // Do something here if the subscription does not exist.
                    throw new ApplicationException(String.Format(
                        "A subscription to '{0}' does not exists on {1}",
                        publicationName, subscriberName));
                }
            }
            catch (Exception ex)
            {
                // Do appropriate error handling here.
                throw new ApplicationException("The subscription could not be reinitialized.", ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Define server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"

' Create a connection to the Subscriber.
Dim conn As ServerConnection = New ServerConnection(subscriberName)

Dim subscription As TransPullSubscription

Try
    ' Connect to the Subscriber.
    conn.Connect()

    ' Define subscription properties.
    subscription = New TransPullSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = subscriptionDbName
    subscription.PublisherName = publisherName
    subscription.PublicationDBName = publicationDbName
    subscription.PublicationName = publicationName

    ' If the pull subscription and the job exists, mark the subscription
    ' for reinitialization and start the agent job.
    If subscription.LoadProperties() And (Not subscription.AgentJobId Is Nothing) Then
        subscription.Reinitialize()
        subscription.SynchronizeWithJob()
    Else
        ' Do something here if the subscription does not exist.
        Throw New ApplicationException(String.Format( _
         "A subscription to '{0}' does not exists on {1}", _
         publicationName, subscriberName))
    End If
Catch ex As Exception
    ' Do appropriate error handling here.
    Throw New ApplicationException("The subscription could not be reinitialized.", ex)
Finally
    conn.Disconnect()
End Try

请参阅

参考

TransPullSubscription 类

Microsoft.SqlServer.Replication 命名空间