I have tried to add the table automatically to transactional replication by using below script.However, I am getting the error.Could you please help me to solve this problem.
use AAAEXEC sp_changepublication@publication ='AAA',@property ='allow_anonymous',@value ='False' GOEXEC sp_changepublication@publication ='AAA',@property ='immediate_sync',@value ='false'createtable#rtables(name varchar(100))insertinto#rtables(name)select objectname from ddl_log where is_replicated=0declare@count int;declare@table varchar(100);declare@flag_pk int;select@count=count(*)from#rtablesWHILE@count >0BEGINselecttop1@table=name from#rtablesSELECT@flag_pk =1FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE ='PRIMARY KEY'AND TABLE_NAME = N'@table'AND TABLE_SCHEMA ='dbo'If@flag_pk =1BEGINexec sp_addarticle @publication = N'AAA',@article = N'@table',@source_owner = N'dbo',@source_object ='@table'EXEC sp_addsubscription@publication = N'AAA',@article = N'@table',@subscriber = N'AAA',@destination_db = N'AAA'ENDSET@count =@count -1;deletefrom#rtables where name=@tableEND;droptable#rtablesEXEC sp_refreshsubscriptions @publication = N'AAA'-- Start the Snapshot Agent job.EXEC sp_startpublication_snapshot @publication = N'AAA'EXEC sp_changepublication@publication ='AAA',@property ='allow_anonymous',@value ='True'EXEC sp_changepublication@publication ='AAA',@property ='immediate_sync',@value ='true'
Here is the Output:
The publication was updated successfully.
The publication was updated successfully.
(41 row(s) affected)
(1 row(s) affected)
(5 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
Job ‘servername-AAA-AAA-26' started successfully.
Msg 20011, Level 16, State 1, Procedure sp_MSrepl_changepublication, Line 1319
Cannot set incompatible publication properties. The 'allow_anonymous' property of a publication depends on the 'immediate_sync' property.
The publication was updated successfully.