How to: Synchronize a Pull Subscription (Replication Programming)
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.
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
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 SQL Server 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
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 SQL Server Authentication, you must also specify the following arguments:
-DistributorLogin
-DistributorPassword
-DistributorSecurityMode = 0
-PublisherLogin
-PublisherPassword
-PublisherSecurityMode = 0
-SubscriberLogin
-SubscriberPassword
-SubscriberSecurityMode = 0
Example
The following example starts the Distribution Agent to synchronize a pull subscription. All connections are made using Windows Authentication.
REM -- Declare the variables.
SET Publisher=%instancename%
SET Subscriber=%instancename%
SET PublicationDB=AdventureWorks2008R2
SET SubscriptionDB=AdventureWorks2008R2Replica
SET Publication=AdvWorksProductsTran
REM -- Start the Distribution Agent.
REM -- The following command must be supplied without line breaks.
"C:\Program Files\Microsoft SQL Server\100\COM\DISTRIB.EXE" -Subscriber %Subscriber%
-SubscriberDB %SubscriptionDB% -SubscriberSecurityMode 1 -Publication %Publication%
-Publisher %Publisher% -PublisherDB %PublicationDB% -Distributor %Publisher%
-DistributorSecurityMode 1 -Continuous -SubscriptionType 1
The following example starts the Merge Agent to synchronize a pull subscription. All connections are made using Windows Authentication.
REM -- Declare the variables.
SET Publisher=%instancename%
SET Subscriber=%instancename%
SET PublicationDB=AdventureWorks2008R2
SET SubscriptionDB=AdventureWorks2008R2Replica
SET Publication=AdvWorksSalesOrdersMerge
REM --Start the Merge Agent with concurrent upload and download processes.
REM -- The following command must be supplied without line breaks.
"C:\Program Files\Microsoft SQL Server\100\COM\REPLMERG.EXE" -Publication %Publication%
-Publisher %Publisher% -Subscriber %Subscriber% -Distributor %Publisher%
-PublisherDB %PublicationDB% -SubscriberDB %SubscriptionDB% -PublisherSecurityMode 1
-OutputVerboseLevel 2 -SubscriberSecurityMode 1 -SubscriptionType 1 -DistributorSecurityMode 1
-Validate 3 -ParallelUploadDownload 1