Programming Replication Agent Executables

Replication agents can be controlled programmatically in the following ways:

Directly invoking replication agents from the command prompt enables agents to be programmatically accessed from command-line scripting in batch files. When an agent is invoked from the command prompt, it runs under the Microsoft Windows security account of the user that invoked the agent or started the batch file.

Instances of the following replication agents can be run using executable files.

When invoking replication agents, you can use performance profiles to automatically pass a defined set of parameters to the agent executable. For more information, see 复制代理配置文件.

Examples

The following examples show how to invoke replication agents from the command prompt. Replication agents can also be invoked using Replication Management Objects (RMO) and Replication ActiveX controls. For more information, see Programming Replication Synchronization Tasks and Programming Replication Using ActiveX Controls.

ms147886.note(zh-cn,SQL.90).gif注意:
Line breaks in these examples were added to improve readability. In a batch file, commands must be made in a single line.

Running the Snapshot Agent

This example batch file invokes the Snapshot Agent from the command prompt to generate a snapshot for the AdvWorksSalesOrdersMerge publication.

REM -- Declare variables
SET Publisher=%InstanceName%
SET PublicationDB=AdventureWorks 
SET Publication=AdvWorksSalesOrdersMerge 

REM --Start the Snapshot Agent to generate the snapshot for AdvWorksSalesOrdersMerge.
"C:\Program Files\Microsoft SQL Server\90\COM\SNAPSHOT.EXE" -Publication %Publication% 
-Publisher %Publisher% -Distributor %Publisher% -PublisherDB %PublicationDB% 
-ReplicationType 2 -OutputVerboseLevel 1 -DistributorSecurityMode 1 

Running the Distribution Agent

This example batch file invokes the Distribution Agent from the command prompt to continuously replicate changes from the AdvWorksProductTran publication to a push subscriber.

REM -- Declare the variables.
SET Publisher=%instancename%
SET Subscriber=%instancename%
SET PublicationDB=AdventureWorks
SET SubscriptionDB=AdventureWorksReplica 
SET Publication=AdvWorksProductsTran

REM -- Start the Distribution Agent with four subscription streams.
REM -- The following command must be supplied without line breaks.
"C:\Program Files\Microsoft SQL Server\90\COM\DISTRIB.EXE" -Subscriber %Subscriber% 
-SubscriberDB %SubscriptionDB% -SubscriberSecurityMode 1 -Publication %Publication% 
-Publisher %Publisher% -PublisherDB %PublicationDB% -Distributor %Publisher% 
-DistributorSecurityMode 1 -Continuous -SubscriptionType 0 -SubscriptionStreams 4 

Running the Merge Agent

This example batch file invokes the Merge Agent from the command prompt to synchronize a pull subscription to the AdvWorksSalesOrdersMerge publication.

REM -- Declare the variables.
SET Publisher=%instancename%
SET Subscriber=%instancename%
SET PublicationDB=AdventureWorks
SET SubscriptionDB=AdventureWorksReplica 
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\90\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 

请参阅

概念

Replication Programming

帮助和信息

获取 SQL Server 2005 帮助