SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Merge replication script


Merge replication script

Author
Message
Gaurav-934012
Gaurav-934012
SSC-Enthusiastic
SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)

Group: General Forum Members
Points: 171 Visits: 107
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
Graeme100
Graeme100
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6801 Visits: 825
It's not the comma at the end of the declared variables is it ?

Regards
Graeme



noeld
noeld
SSC Guru
SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)

Group: General Forum Members
Points: 83262 Visits: 2084
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
Gaurav-934012
Gaurav-934012
SSC-Enthusiastic
SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)

Group: General Forum Members
Points: 171 Visits: 107
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
noeld
noeld
SSC Guru
SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)SSC Guru (83K reputation)

Group: General Forum Members
Points: 83262 Visits: 2084
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search