Share via


TransPullSubscription.Reinitialize Method

Marks the pull subscription for reinitialization.

Namespace:  Microsoft.SqlServer.Replication
Assembly:  Microsoft.SqlServer.Rmo (in Microsoft.SqlServer.Rmo.dll)

Syntax

public void Reinitialize()

Remarks

After calling the Reinitialize method, you must start synchronization to reinitialize the subscription. For more information, see NIB Reinitialize a Subscription (RMO Programming).

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.

Examples

          // 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();
            }

See Also

Reference

TransPullSubscription Class

Microsoft.SqlServer.Replication Namespace