Skip to content

Latest commit

 

History

History
234 lines (131 loc) · 16 KB

File metadata and controls

234 lines (131 loc) · 16 KB
title Synchronize a Pull Subscription | Microsoft Docs
ms.custom
ms.date 06/13/2017
ms.prod sql-server-2014
ms.reviewer
ms.technology replication
ms.topic conceptual
helpviewer_keywords
pull subscriptions [SQL Server replication], synchronizing
synchronization [SQL Server replication], pull subscriptions
subscriptions [SQL Server replication], pull
ms.assetid 3ca24b23-fdc3-408e-8208-a2ace48fc8e3
author MashaMSFT
ms.author mathoma
manager craigg

Synchronize a Pull Subscription

This topic describes how to synchronize a pull subscription in [!INCLUDEssCurrent] by using [!INCLUDEssManStudioFull], replication agents, or Replication Management Objects (RMO).

Using SQL Server Management Studio

Subscriptions are synchronized by the Distribution Agent (for snapshot and transactional replication) or the Merge Agent (for merge replication). Agents can run continuously, run on demand, or run on a schedule. For more information about specifying synchronization schedules, see Specify Synchronization Schedules.

Synchronize a subscription on demand from the Local Subscriptions folder in [!INCLUDEssManStudioFull].

To synchronize a pull subscription on demand in Management Studio

  1. Connect to the Subscriber in [!INCLUDEssManStudio], and then expand the server node.

  2. Expand the Replication folder, and then expand the Local Subscriptions folder.

  3. Right-click the subscription you want to synchronize, and then click View Synchronization Status.

  4. In the View Synchronization Status - <Subscriber>:<SubscriptionDatabase> dialog box, click Start. When synchronization is complete, the message Synchronization completed is displayed.

  5. Click Close.

Replication Agents

Pull subscriptions can be synchronized programmatically and on-demand by invoking the appropriate replication agent executable file from the command prompt. The replication agent executable file that is invoked will depend on the type of publication to which the pull subscription belongs. For more information, see Replication Agents.

Note

Replication agents connect to the local server using the Windows Authentication credentials of the user who started the agent from the command prompt. These Windows credentials are also used when connecting to remote servers using Windows Integrated Authentication.

To start the distribution agent from the command prompt or from a batch file

  1. From the command prompt or in a batch file, start the Replication Distribution Agent by running distrib.exe, specifying the following command-line arguments:

    • -Publisher

    • -PublisherDB

    • -Distributor

    • -DistributorSecurityMode = 1

    • -Subscriber

    • -SubscriberDB

    • -SubscriberSecurityMode = 1

    • -SubscriptionType = 1

    If you are using [!INCLUDEssNoVersion] Authentication, you must also specify the following arguments:

    • -DistributorLogin

    • -DistributorPassword

    • -DistributorSecurityMode = 0

    • -PublisherLogin

    • -PublisherPassword

    • -PublisherSecurityMode = 0

    • -SubscriberLogin

    • -SubscriberPassword

    • -SubscriberSecurityMode = 0

To start the merge agent from the command prompt or from a batch file

  1. From the command prompt or in a batch file, start the Replication Merge Agent by running replmerg.exe, specifying the following command-line arguments:

    • -Publisher

    • -PublisherDB

    • -PublisherSecurityMode = 1

    • -Publication

    • -Distributor

    • -DistributorSecurityMode = 1

    • -Subscriber

    • -SubscriberSecurityMode = 1

    • -SubscriberDB

    • -SubscriptionType = 1

    If you are using [!INCLUDEssNoVersion] Authentication, you must also specify the following arguments:

    • -DistributorLogin

    • -DistributorPassword

    • -DistributorSecurityMode = 0

    • -PublisherLogin

    • -PublisherPassword

    • -PublisherSecurityMode = 0

    • -SubscriberLogin

    • -SubscriberPassword

    • -SubscriberSecurityMode = 0

Examples (Replication Agents)

The following example starts the Distribution Agent to synchronize a pull subscription. All connections are made using Windows Authentication.

[!code-sqlHowTo#bat_synctranpullsub_10]

The following example starts the Merge Agent to synchronize a pull subscription. All connections are made using Windows Authentication.

[!code-sqlHowTo#bat_syncmergepullsub_10]

Using Replication Management Objects (RMO)

You can synchronize pull subscriptions programmatically by using Replication Management Objects (RMO) and managed code access to replication agent functionalities. The classes you use to synchronize a pull subscription depend on the type of publication to which the subscription belongs.

Note

If you want to start a synchronization that runs autonomously without affecting your application, start the agent asynchronously. However, if you want to monitor the outcome of the synchronization and receive callbacks from the agent during the synchronization process (for example, to display a progress bar), you should start the agent synchronously. For [!INCLUDEmsCoName][!INCLUDEssExpressEd2005] Subscribers, you must start the agent synchronously.

To synchronize a pull subscription to a snapshot or transactional publication

  1. Create a connection to the Subscriber by using the xref:Microsoft.SqlServer.Management.Common.ServerConnection class.

  2. Create an instance of the xref:Microsoft.SqlServer.Replication.TransPullSubscription class, and set the following properties:

    • The subscription database name for xref:Microsoft.SqlServer.Replication.PullSubscription.DatabaseName%2A.

    • The name of the publication to which the subscription belongs for xref:Microsoft.SqlServer.Replication.PullSubscription.PublicationName%2A.

    • The name of the publication database for xref:Microsoft.SqlServer.Replication.PullSubscription.PublicationDBName%2A.

    • The name of the Publisher for xref:Microsoft.SqlServer.Replication.PullSubscription.PublisherName%2A.

    • The connection created in step 1 for xref:Microsoft.SqlServer.Replication.ReplicationObject.ConnectionContext%2A.

  3. Call the xref:Microsoft.SqlServer.Replication.ReplicationObject.LoadProperties%2A method to get the remaining subscription properties. If this method returns false, verify that the subscription exists.

  4. Start the Distribution Agent at the Subscriber in one of the following ways:

    • Call the xref:Microsoft.SqlServer.Replication.TransPullSubscription.SynchronizeWithJob%2A method on the instance of xref:Microsoft.SqlServer.Replication.TransPullSubscription from step 2. This method starts the Distribution Agent asynchronously, and control immediately returns to your application while the agent job is running. You cannot call this method for [!INCLUDEssExpressEd2005] Subscribers or if the subscription was created with a value of false for xref:Microsoft.SqlServer.Replication.PullSubscription.CreateSyncAgentByDefault%2A (the default).

    • Get an instance of the xref:Microsoft.SqlServer.Replication.TransSynchronizationAgent class from the xref:Microsoft.SqlServer.Replication.TransPullSubscription.SynchronizationAgent%2A property, and call the xref:Microsoft.SqlServer.Replication.TransSynchronizationAgent.Synchronize%2A method. This method starts the agent synchronously, and control remains with the running agent job. During synchronous execution, you can handle the xref:Microsoft.SqlServer.Replication.TransSynchronizationAgent.Status event while the agent is running.

      [!NOTE]
      If you specified a value of false for xref:Microsoft.SqlServer.Replication.PullSubscription.CreateSyncAgentByDefault%2A (the default) when you created the pull subscription, you also need to specify xref:Microsoft.SqlServer.Replication.TransSynchronizationAgent.Distributor%2A, xref:Microsoft.SqlServer.Replication.TransSynchronizationAgent.DistributorSecurityMode%2A, and optionally xref:Microsoft.SqlServer.Replication.TransSynchronizationAgent.DistributorLogin%2A and xref:Microsoft.SqlServer.Replication.TransSynchronizationAgent.DistributorPassword%2A because the agent job related metadata for the subscription is not available in MSsubscription_properties.

To synchronize a pull subscription to a merge publication

  1. Create a connection to the Subscriber by using the xref:Microsoft.SqlServer.Management.Common.ServerConnection class.

  2. Create an instance of the xref:Microsoft.SqlServer.Replication.MergePullSubscription class, and set the following properties:

    • The subscription database name for xref:Microsoft.SqlServer.Replication.PullSubscription.DatabaseName%2A.

    • The name of the publication to which the subscription belongs for xref:Microsoft.SqlServer.Replication.PullSubscription.PublicationName%2A.

    • The name of the published database for xref:Microsoft.SqlServer.Replication.PullSubscription.PublicationDBName%2A.

    • The name of the Publisher for xref:Microsoft.SqlServer.Replication.PullSubscription.PublisherName%2A.

    • The connection created in step 1 for xref:Microsoft.SqlServer.Replication.ReplicationObject.ConnectionContext%2A.

  3. Call the xref:Microsoft.SqlServer.Replication.ReplicationObject.LoadProperties%2A method to get the remaining subscription properties. If this method returns false, verify that the subscription exists.

  4. Start the Merge Agent at the Subscriber in one of the following ways:

    • Call the xref:Microsoft.SqlServer.Replication.MergePullSubscription.SynchronizeWithJob%2A method on the instance of xref:Microsoft.SqlServer.Replication.MergePullSubscription from step 2. This method starts the Merge Agent asynchronously, and control immediately returns to your application while the agent job is running. You cannot call this method for [!INCLUDEssExpressEd2005] Subscribers or if the subscription was created with a value of false for xref:Microsoft.SqlServer.Replication.PullSubscription.CreateSyncAgentByDefault%2A (the default).

    • Obtain an instance of the xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent class from the xref:Microsoft.SqlServer.Replication.MergePullSubscription.SynchronizationAgent%2A property, and call the xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.Synchronize%2A method. This method starts the Merge Agent synchronously, and control remains with the running agent job. During synchronous execution, you can handle the xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.Status event while the agent is running.

      [!NOTE]
      If you specified a value of false for xref:Microsoft.SqlServer.Replication.PullSubscription.CreateSyncAgentByDefault%2A (the default) when you created the pull subscription, you also need to specify xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.Distributor%2A, xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.DistributorSecurityMode%2A, xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.PublisherSecurityMode%2A, xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.HostName%2A, xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.SubscriptionType%2A, xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.ExchangeType%2A, and optionally xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.DistributorLogin%2A, xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.DistributorPassword%2A, xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.PublisherLogin%2A, and xref:Microsoft.SqlServer.Replication.MergeSynchronizationAgent.PublisherPassword%2A because the agent job related metadata for the subscription is not available in MSsubscription_properties.

Examples (RMO)

This example synchronizes a pull subscription to a transactional publication, where the agent is started asynchronously using the agent job.

[!code-csharpHowTo#rmo_SyncTranPullSub_WithJob]

[!code-vbHowTo#rmo_vb_SyncTranPullSub_WithJob]

This example synchronizes a pull subscription to a transactional publication, where the agent is started synchronously.

[!code-csharpHowTo#rmo_SyncTranPullSub]

[!code-vbHowTo#rmo_vb_SyncTranPullSub]

This example synchronizes a pull subscription to a merge publication, where the agent is started asynchronously using the agent job.

[!code-csharpHowTo#rmo_SyncMergePullSub_WithJob]

[!code-vbHowTo#rmo_vb_SyncMergePullSub_WithJob]

This example synchronizes a pull subscription to a merge publication, where the agent is started synchronously.

[!code-csharpHowTo#rmo_SyncMergePullSub]

[!code-vbHowTo#rmo_vb_SyncMergePullSub]

This example synchronizes a pull subscription to a merge publication using Web synchronization. The subscription was created without the agent job and related subscription metadata, so the agent must be started synchronously and additional subscription information is supplied.

[!code-csharpHowTo#rmo_SyncMergePullSub_NoJobWebSync]

[!code-vbHowTo#rmo_vb_SyncMergePullSub_NoJobWebSync]

See Also

Synchronize Data
Create a Pull Subscription
Replication Security Best Practices