Merge replication script

  • Hi All

    I have set up the merge replication in SSMS (management studio). I am able to perform merge replication between subscriber and publisher. But the synchronization process has to be started manually.

    I am using a script to start the synchronization but I am getting some errors.

    Script and error details are as follows

    Script:

    declare @cmd varchar(4000),

    @publisher varchar(400),

    @publicationDB varchar(400),

    @publication varchar(400),

    @subscriptionDB varchar(400),

    set @publisher='publisher_name'

    set @publicationDB='db_name'

    set @publication='publication_name'

    set @subscriptionDB='db_name1'

    /* The following command should be all on one line. It is displayed on multiple

    lines here because of the limitations of the page. */

    set @cmd="C:\Program Files\Microsoft SQL Server\90\COM\REPLMERG.EXE" -Publication @publication -Publisher @publisher -Subscriber @publisher -Distributor @publisher -PublisherDB @publicationDB -SubscriberDB @subscriptionDB -PublisherSecurityMode 1 -PublisherLogin @login -PublisherPassword @password -OutputVerboseLevel 2 -SubscriberSecurityMode 1 -SubscriberLogin @login -SubscriberPassword @password -SubscriptionType 1 -DistributorSecurityMode 1 -DistributorLogin @login -DistributorPassword @password -Validate 3 -ParallelUploadDownload 0

    exec xp_cmdshell '@cmd'

    go

    Error:

    Msg 102, Level 15, State 1, Line 17

    Incorrect syntax near '@publication'.

    Any idea how can I get rid of this error?

    Thanks

    Gaurav

  • It's not the comma at the end of the declared variables is it ?

    Regards

    Graeme

  • Gaurav (1/12/2009)


    Hi All

    I have set up the merge replication in SSMS (management studio). I am able to perform merge replication between subscriber and publisher. But the synchronization process has to be started manually.

    I am using a script to start the synchronization but I am getting some errors.

    Script and error details are as follows

    Script:

    declare @cmd varchar(4000),

    @publisher varchar(400),

    @publicationDB varchar(400),

    @publication varchar(400),

    @subscriptionDB varchar(400),

    set @publisher='publisher_name'

    set @publicationDB='db_name'

    set @publication='publication_name'

    set @subscriptionDB='db_name1'

    /* The following command should be all on one line. It is displayed on multiple

    lines here because of the limitations of the page. */

    set @cmd="C:\Program Files\Microsoft SQL Server\90\COM\REPLMERG.EXE" -Publication @publication -Publisher @publisher -Subscriber @publisher -Distributor @publisher -PublisherDB @publicationDB -SubscriberDB @subscriptionDB -PublisherSecurityMode 1 -PublisherLogin @login -PublisherPassword @password -OutputVerboseLevel 2 -SubscriberSecurityMode 1 -SubscriberLogin @login -SubscriberPassword @password -SubscriptionType 1 -DistributorSecurityMode 1 -DistributorLogin @login -DistributorPassword @password -Validate 3 -ParallelUploadDownload 0

    exec xp_cmdshell '@cmd'

    go

    Error:

    Msg 102, Level 15, State 1, Line 17

    Incorrect syntax near '@publication'.

    Any idea how can I get rid of this error?

    Thanks

    Gaurav

    The parameters should be decoded on the @cmd variable like:

    /* The following command should be all on one line. It is displayed on multiple

    lines here because of the limitations of the page. */

    set @cmd='"C:\Program Files\Microsoft SQL Server\90\COM\REPLMERG.EXE" -Publication ' + @publication + ' -Publisher ' + @publisher + ' -Subscriber ' + @publisher + ' -Distributor ' + @publisher + ' -PublisherDB ' + @publicationDB + ' -SubscriberDB ' + @subscriptionDB +' -PublisherSecurityMode 1 -PublisherLogin ' + @login + ' -PublisherPassword '+ @password + '-OutputVerboseLevel 2 -SubscriberSecurityMode 1 -SubscriberLogin ' + @login + ' -SubscriberPassword ' + @password + ' -SubscriptionType 1 -DistributorSecurityMode 1 -DistributorLogin ' + @login + ' -DistributorPassword ' + @password + ' -Validate 3 -ParallelUploadDownload 0 '


    * Noel

  • Thanks a lot I got rid of the error

    and the script worked fine if both the publisher and subscriber are on the same machine, however if the subscriber and publisher are on different machines It gave me the following errors

    1.The process could not connect to the distributor

    2. Login failed for the user 'NT AUTHORITY\ANONYMOUS LOGON

    But If I use SSMS to synchronize database between publisher and subscriber it works fine.

    I was just wondering why merge replication works in SSMS but it does not work when I use the above script.

    Thanks

    Gaurav

  • xp_cmdshell uses "SQL Server Account" to run under if there is no proxy associated with it.

    You need to run that script under a domain account with the right permissions.

    You must also ensure that there is connectivity between the machines and that the account you are passing are correctly setup in both machines.


    * Noel

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply