I'm trying to set up a 2 mode peer 2 peer configuration but I'm having a bit of a problem getting it to work.
This is the error I see:
Command attempted:
if @@trancount > 0 rollback tran
(Transaction sequence number: 0x0000804400001379009900000002, Command ID: 1)
Error messages:
Explicit value must be specified for identity column in table 'MSpeer_lsns' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column. (Source: MSSQLServer, Error number: 545)
Get help: http://help/545
Explicit value must be specified for identity column in table 'MSpeer_lsns' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column. (Source: MSSQLServer, Error number: 545)
Get help: http://help/545
The procedure sys.sp_MSaddpeerlsn failed to INSERT into the resource MSpeer_lsns.. Server error = 0. (Source: MSSQLServer, Error number: 21499)
Get help: http://help/21499
What I've done (using T-SQL) is create a backup from the "source db" and restore the database to each of the peer nodes.
Then search for the identity columns in the articles I'm going to replicate I reseed them so each node does not have overlapping identities, then create the publication, add the articles, and then the subscribers and finally the distributor agent.
I've been trying to find my mistake for a couple of days now, so hopefully someone here knows what I've missed or have done wrong.
Script template for creating the publications:
-- Enabling the replication database
use master
exec sp_replicationdboption @dbname = <@db>, @optname = N'publish', @value = N'true'
-- Check if the publication exists
USE Distribution
IF EXISTS (SELECT publication FROM MSpublications WHERE publication = '<@pubName>')
BEGIN
use [<@db>]
EXEC sp_changedbowner 'sa'
BEGIN TRY
exec sp_removedbreplication N'<@pubName>'
exec sp_droppublication @publication = N'<@pubName>'
END TRY
BEGIN CATCH
END CATCH
END
-- Adding the transactional publication
use [<@db>]
exec sp_addpublication @publication = '<@pubName>'
, @description = N'<@pubDescription>'
, @sync_method = N'native'
, @retention = 0
, @allow_push = N'true'
, @allow_pull = N'true'
, @allow_anonymous = N'false'
, @enabled_for_internet = N'false'
, @snapshot_in_defaultfolder = N'true'
, @compress_snapshot = N'false'
, @ftp_port = 21
, @ftp_login = N'anonymous'
, @allow_subscription_copy = N'false'
, @add_to_active_directory = N'false'
, @repl_freq = N'continuous'
, @status = N'active'
, @independent_agent = N'true'
, @immediate_sync = N'true'
, @allow_sync_tran = N'false'
, @autogen_sync_procs = N'false'
, @allow_queued_tran = N'false'
, @allow_dts = N'false'
, @replicate_ddl = 1
, @allow_initialize_from_backup = N'true'
, @enabled_for_p2p = N'true'
, @enabled_for_het_sub = N'false'
script(template) to add articles:
-- add articles to a publication (<@pubName>)
USE [<@db>]
DECLARE @filter_articles BIT = <@filterFlag>;
DECLARE @articleCursor CURSOR, @artSchema nvarchar(50), @artName nvarchar(100)
DECLARE @schemaNname nvarchar(100);
IF @filter_articles = 1
BEGIN
SET @articleCursor = CURSOR FAST_FORWARD FOR
SELECT object_schema_name(ao.object_id) as [schema], ao.name
FROM sys.extended_properties as p
INNER JOIN sys.all_objects as ao
ON ao.object_id = p.major_id
WHERE p.value = 'p2p'
AND OBJECTPROPERTY(ao.object_id,'TableHasPrimaryKey')= 1
END
ELSE
BEGIN
SET @articleCursor = CURSOR FAST_FORWARD FOR
SELECT object_schema_name(ao.object_id) as [schema], ao.name
FROM sys.all_objects as ao
WHERE OBJECTPROPERTY(ao.object_id,'TableHasPrimaryKey')= 1
END
OPEN @articleCursor
FETCH NEXT FROM @articleCursor INTO @artSchema, @artName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @schemaNname = @artSchema + '.' + @artName
-- modify the identity seed if present
IF EXISTS (
SELECT c.name FROM sys.all_columns as c
INNER JOIN sys.all_objects as o ON o.object_id = c.object_id
INNER JOIN sys.schemas as s ON s.schema_id = o.schema_id
WHERE o.name = @artName AND s.name = @artSchema and c.is_identity = 1
)
BEGIN
DBCC CHECKIDENT (@schemaNname, RESEED, <@seed>);
END
exec sp_addarticle @publication =N'<@pubName>'
, @article = @schemaNname
, @source_owner = @artSchema
, @source_object = @artName
, @type = N'logbased'
, @description = N''
, @creation_script = null
, @pre_creation_cmd = N'drop'
, @schema_option = 0x0000000008037FDF
, @identityrangemanagementoption = N'manual'
, @destination_table = @artName
, @destination_owner = @artSchema
, @status = 16
, @vertical_partition = N'false'
, @ins_cmd = N'CALL sp_MSins_dbotrx'
, @del_cmd = N'CALL sp_MSdel_dbotrx'
, @upd_cmd = N'SCALL sp_MSupd_dbotrx'
FETCH NEXT FROM @articleCursor INTO @artSchema, @artName
END
CLOSE @articleCursor
DEALLOCATE @articleCursor
subscriber script(template):
-----------------BEGIN: Script to be run at Publisher '<@publisher>'-----------------
use [<@db>]
-- check if the subscription exists
declare @found as int
EXEC sp_helpsubscription
@publication = N'<@pubName>',
@subscriber = N'<@subscriber>',
@destination_db = N'[<@db>]',
@found = @found OUTPUT;
IF @found = 1
BEGIN -- if it exists drop it and re-create it.
exec sp_dropsubscription
@publication = N'<@pubName>'
, @subscriber = N'<@subscriber>'
, @destination_db = N'<@db>'
, @article = N'all';
END
exec sp_addsubscription @publication = N'<@pubName>'
, @subscriber = N'<@subscriber>'
, @destination_db = N'<@db>'
, @subscription_type = N'Push'
, @sync_type = N'replication support only'
, @article = N'all'
, @update_mode = N'read only'
, @subscriber_type = 0
Finally script(template) for adding the distributor agent:
exec sp_addpushsubscription_agent @publication = N'<@pubName>'
, @subscriber = N'<@subscriber>'
, @subscriber_db = N'<@db>'
, @job_login = N'<@agentUsername>'
, @job_password = N'<@agentPassword>'
, @subscriber_security_mode = 0
, @subscriber_login = N'<@subscriberUsername>'
, @subscriber_password = N'<@subscriberPassword>'
, @frequency_type = 64
, @frequency_interval = 0
, @frequency_relative_interval = 0
, @frequency_recurrence_factor = 0
, @frequency_subday = 0
, @frequency_subday_interval = 0
, @active_start_time_of_day = 0
, @active_end_time_of_day = 235959
, @active_start_date = 20140404
, @active_end_date = 99991231
, @enabled_for_syncmgr = N'False'
, @dts_package_location = N'Distributor'
Developer Frog Haven Enterprises