複寫代理程式可執行檔概念

複寫代理程式可以用下列方式以程式設計方式來控制:

  • Microsoft.SqlServer.Replication 命名空間中使用 Managed 代理程式來程式設計介面。

  • 從命令提示字元以一組提供的參數來叫用代理程式可執行檔。

從命令提示字元直接叫用複寫代理程式,可讓代理程式從批次檔的命令列指令碼中以程式設計的方式存取。從命令提示字元叫用代理程式時,它會在叫用代理程式或是啟動批次檔之該使用者的 Microsoft Windows 安全性帳戶之下執行。

下列複寫代理程式的執行個體,可以使用可執行檔來執行。

叫用複寫代理程式時,您可以使用效能設定檔,將一組定義的參數自動傳遞到代理程式可執行檔。如需詳細資訊,請參閱<複寫代理程式設定檔>。

範例

下列範例顯示如何從命令提示字元叫用複寫代理程式。複寫代理程式也可以透過複寫管理物件 (RMO) 來叫用。如需詳細資訊,請參閱<同步處理訂閱 (複寫)>。

[!附註]

在這些範例中加入了分行符號,以提升可讀性。在批次檔中,必須在單一行中撰寫命令。

執行快照集代理程式。

這個範例批次檔會從命令提示字元叫用快照集代理程式,以產生 AdvWorksSalesOrdersMerge 發行集的快照集。

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

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

執行散發代理程式。

這個範例批次檔會從命令提示字元叫用散發代理程式,以繼續從 AdvWorksProductTran 發行集將變更複寫到發送訂閱者。

REM -- Declare the variables.
SET Publisher=%instancename%
SET Subscriber=%instancename%
SET PublicationDB=AdventureWorks2008R2
SET SubscriptionDB=AdventureWorks2008R2Replica 
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\100\COM\DISTRIB.EXE" -Subscriber %Subscriber% 
-SubscriberDB %SubscriptionDB% -SubscriberSecurityMode 1 -Publication %Publication% 
-Publisher %Publisher% -PublisherDB %PublicationDB% -Distributor %Publisher% 
-DistributorSecurityMode 1 -Continuous -SubscriptionType 0 -SubscriptionStreams 4 

執行合併代理程式

這個範例批次檔會從命令提示字元叫用合併代理程式,以便將提取訂閱同步處理到 AdvWorksSalesOrdersMerge 發行集。

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 

請參閱

概念