Im using sql server 2012 and its replication feature. Here im trying to manually create a publication and adding articles to it using script. I was able to create the publication successfully, but i have problems adding articles to it.
This is my script to add articles
EXEC ScriptDB.dbo.sp_addarticle
@publication = 'PublicationOne',
@article = 'Departments',
@source_object = 'Departments',
@source_owner = 'dbo',
@type = N'logbased',
@schema_option = 0x000000000803509F,
@identityrangemanagementoption = N'manual',
@pre_creation_cmd = N'none'
The most important thing is, Departments table is in PublisherDB database and im runing this script from ScriptDB database. As i will be having many publishers, i will pass these values dynamically.
When i execute the above script, i get the following error
Msg 14027, Level 11, State 1, Procedure sp_MSrepl_addarticle, Line 590 [dbo].[Departments] does not exist in the current database.
Departments table does not exist in ScriptDB, but it is in PublisherDB database. So i changed the script to
EXEC PublisherDB.dbo.sp_addarticle
@publication = 'PublicationOne',
@article = 'Departments',
@source_object = 'Departments',
@source_owner = 'dbo',
@type = N'logbased',
@schema_option = 0x000000000803509F,
@identityrangemanagementoption = N'manual',
@pre_creation_cmd = N'none'
now it says,
Msg 20026, Level 11, State 1, Procedure sp_MSreinit_article, Line 40 The publication 'PublicationOne' does not exist.
Tell me something, can’t i run the script on another database to create a publication.
For example, consider this case, I have a master database and two publisher databases. I want to create two separate publication (one for each publisher database). Now can i execute the above script in master database to create publishers (using two publisher databases). Is this possible to implement.
Please help.
sp_addarticle must be executed at the Publisher on the publication database. If you wish to publish the PublisherDB database then create the publication for PublisherDB and call sp_addarticle on the PublisherDB database to add articles to the publication.