Search This Blog

Friday, August 29, 2008

Programming Replication Distribution Agent Executable

Distribution replication agent can be controlled by programmatically described below,
You can copy and paste below code in a batch file and then execute that batch file after replacing the required information with your actual parameters. It will execute the Distribution agent.

Required Parameters:
Distributor
: Distributor instance name
DistributorSecurityMode: 0 for SQL Server authentication that is default, and 1 for window authentication

Publisher: Publisher instance name
PublisherDB: Publinsher's database
Publicaiton: Publication name

Subscriber: Subscriber instance name
SubscriptionDB: Subscriber's database
SubcriberSecurityMode: 0 for SQL Server authentication that is default, and 1 for window authentication
SubscriptionType: Subcriber's connection used by the agent, 0=SQL Server, 1=ODBC Datasource, 2=OLE DB Datasource
SubscriptionStream: number of connection per distribtion agent to apply batches of changes in parallel to a subscriber (1 to 64)

Script:

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.
"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

It will execute the subscriber’s distribution agent for specified publication with SQL Server subscription type having four Parallel threads to replicate the change in windows authentication mode.

No comments: