Replication Agent Executables Concepts

適用於:SQL ServerAzure SQL 受控執行個體

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

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

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

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

您可以使用可執行檔來執行下列複寫代理程式的實例。

叫用複寫代理程式時,您可以使用效能設定檔,將一組定義的參數自動傳遞至代理程式可執行檔。 如需相關資訊,請參閱 Replication Agent Profiles

範例

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

注意

已新增這些範例中的分行符號,以改善可讀性。 在批次檔中,必須在單一行中撰寫命令。

執行快照集代理程式

這個範例批次檔會從命令提示字元叫用快照集代理程式,以產生 AdvWorksSalesOrdersMerge 發行集的 快照集。 (下列腳本使用 SQL Server 2016 (13.x) 檔案的路徑(版本 130)。 您應該調整腳本,以指向 SQL Server 版本的檔案。

REM -- Declare variables  
SET Publisher=%InstanceName%;  
SET PublicationDB=AdventureWorks2022;   
SET Publication=AdvWorksSalesOrdersMerge;   
  
REM --Start the Snapshot Agent to generate the snapshot for AdvWorksSalesOrdersMerge.  
"C:\Program Files\Microsoft SQL Server\130\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=AdventureWorks2022;  
SET SubscriptionDB=AdventureWorks2022Replica;   
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\130\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=AdventureWorks2022;  
SET SubscriptionDB=AdventureWorks2022Replica;   
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\130\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 ;