sql server replication:
Gav, here is an article that might help clarify a little: http://www.replicationanswers.com/CentralSubscriberArticle.asp I'm not too sure of the exact source of this error though. PLS can you confirm the definition of the PK on CCSYSTEM on the central subscriber and check the contents of the BCP snapshot file as well. Paul Ibison
Hi all, I'm fairly new to SQL replication and I've been trying to setup a 'central subscriber' topology using transaction replication. First publisher went smoothly... second publisher, snapshot worked smoothly but now is coming up with a distribution agent error: The process could not bulk copy into table '"CCSYSTEM"'. Violation of PRIMARY KEY constraint 'PK__CCSYSTEM__0C70CFB4'. Cannot insert duplicate key in object 'CCSYSTEM'. I have checked the tables and there aren't any rows that conflict, for the table in question there is only one row for each publisher: primary key (branchid, record_number) 'server A' NE 1 'server B' IW 1 'central sub' NE 1 IW 1 I'm only getting error on one of the publishers not both. Any help would be great, thanks
Hi Paul, Thanks for the reply and the link (I had a good read of that before I started). The generated script for the table including primary keys looks like this (removed columns you wouldn't be interested in): /****** Object: Table [dbo].[CCSYSTEM] Script Date: 23/08/2007 15:56:37 ******/ CREATE TABLE [dbo].[CCSYSTEM] ( [BRANCHID] [varchar] (2) COLLATE Latin1_General_CI_AS NOT NULL , [RECORD_NUMBER] [int] NOT NULL , [msrepl_tran_version] [uniqueidentifier] NOT NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[CCSYSTEM] WITH NOCHECK ADD PRIMARY KEY CLUSTERED ( [BRANCHID], [RECORD_NUMBER] ) ON [PRIMARY] GO ALTER TABLE [dbo].[CCSYSTEM] ADD CONSTRAINT [DF__CCSYSTEM__msrepl__0D6FE0E5] DEFAULT (newid()) FOR [msrepl_tran_version] GO You say to check the contents of the BCP snapshot file, should I assume I should be doing this on the publisher that is displaying the error? I've just had a quick look and found the bcp file but not sure what I'm looking at how can I check this? Regards Gav [quoted text, click to view] "Paul Ibison" wrote: > Gav, > here is an article that might help clarify a little: > http://www.replicationanswers.com/CentralSubscriberArticle.asp > I'm not too sure of the exact source of this error though. PLS can you > confirm the definition of the PK on CCSYSTEM on the central subscriber and > check the contents of the BCP snapshot file as well. > Paul Ibison > >
Gav, have a look at the BCP text file that contains the data to be inserted and compare this to the contents of the central subscriber table. Cheers, Paul Ibison
Sorry Paul, I did say I was fairly new to replication (this is the first time I've done it). I'm not sure what I should be looking at. I found a .bcp file which I opened in notepad and it didn't make much sense. I opened the .sch file, that made more sense: ------Begin sch file SET QUOTED_IDENTIFIER ON GO if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CCSYSTEM]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) BEGIN CREATE TABLE [CCSYSTEM] ( [BRANCHID] [varchar] (2) NOT NULL , [RECORD_NUMBER] [int] NOT NULL , [TYPE] [varchar] (80) NULL , [CURRPERIOD] [float] NULL , [YEAR] [float] NULL , [INCRTXNO] [float] NULL , [PDAYINCR] [float] NULL , [DBINCR] [float] NULL , [CASHTXNO] [float] NULL , [PDAYCASH] [float] NULL , [DBCASH] [float] NULL , [ADJSTXNO] [float] NULL , [PDAYADJS] [float] NULL , [DBADJS] [float] NULL , [msrepl_tran_version] [uniqueidentifier] NOT NULL CONSTRAINT [DF__CCSYSTEM__msrepl__36C6FC33] DEFAULT (newid()) ) END GO drop procedure [sp_MSins_CCSYSTEM] go if exists (select * from sysobjects where type = 'P' and name = 'sp_MSins_CCSYSTEM') drop proc [sp_MSins_CCSYSTEM] go create procedure [sp_MSins_CCSYSTEM] @c1 varchar(2),@c2 int,@c3 varchar(80),@c4 float,@c5 float,@c6 float,@c7 float,@c8 float,@c9 float,@c10 float,@c11 float,@c12 float,@c13 float,@c14 float,@c15 uniqueidentifier AS BEGIN if not exists (select * from [CCSYSTEM] where ( [BRANCHID] = @c1 and [RECORD_NUMBER] = @c2 ) ) BEGIN insert into [CCSYSTEM]( [BRANCHID], [RECORD_NUMBER], [TYPE], [CURRPERIOD], [YEAR], [INCRTXNO], [PDAYINCR], [DBINCR], [CASHTXNO], [PDAYCASH], [DBCASH], [ADJSTXNO], [PDAYADJS], [DBADJS], [msrepl_tran_version] ) values ( @c1, @c2, @c3, @c4, @c5, @c6, @c7, @c8, @c9, @c10, @c11, @c12, @c13, @c14, @c15 ) END END go create procedure [sp_MSins_CCSYSTEM];2 @c1 varchar(2),@c2 int,@c3 varchar(80),@c4 float,@c5 float,@c6 float,@c7 float,@c8 float,@c9 float,@c10 float,@c11 float,@c12 float,@c13 float,@c14 float,@c15 uniqueidentifier as if exists ( select * from [CCSYSTEM] where [BRANCHID] = @c1 and [RECORD_NUMBER] = @c2 ) begin update [CCSYSTEM] set [TYPE] = @c3,[CURRPERIOD] = @c4,[YEAR] = @c5,[INCRTXNO] = @c6,[PDAYINCR] = @c7,[DBINCR] = @c8,[CASHTXNO] = @c9,[PDAYCASH] = @c10,[DBCASH] = @c11,[ADJSTXNO] = @c12,[PDAYADJS] = @c13,[DBADJS] = @c14,[msrepl_tran_version] = @c15 where [BRANCHID] = @c1 and [RECORD_NUMBER] = @c2 end else begin insert into [CCSYSTEM] ( [BRANCHID],[RECORD_NUMBER],[TYPE],[CURRPERIOD],[YEAR],[INCRTXNO],[PDAYINCR],[DBINCR],[CASHTXNO],[PDAYCASH],[DBCASH],[ADJSTXNO],[PDAYADJS],[DBADJS],[msrepl_tran_version] ) values ( @c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8,@c9,@c10,@c11,@c12,@c13,@c14,@c15 ) end go drop procedure [sp_MSupd_CCSYSTEM] go if exists (select * from sysobjects where type = 'P' and name = 'sp_MSupd_CCSYSTEM') drop proc [sp_MSupd_CCSYSTEM] go create procedure [sp_MSupd_CCSYSTEM] @c1 varchar(2),@c2 int,@c3 varchar(80),@c4 float,@c5 float,@c6 float,@c7 float,@c8 float,@c9 float,@c10 float,@c11 float,@c12 float,@c13 float,@c14 float,@c15 uniqueidentifier,@c16 varchar(2),@c17 int,@c18 varchar(80),@c19 float,@c20 float,@c21 float,@c22 float,@c23 float,@c24 float,@c25 float,@c26 float,@c27 float,@c28 float,@c29 float,@c30 uniqueidentifier as if @c16 = @c1 and @c17 = @c2 begin update [CCSYSTEM] set [TYPE] = @c18 ,[CURRPERIOD] = @c19 ,[YEAR] = @c20 ,[INCRTXNO] = @c21 ,[PDAYINCR] = @c22 ,[DBINCR] = @c23 ,[CASHTXNO] = @c24 ,[PDAYCASH] = @c25 ,[DBCASH] = @c26 ,[ADJSTXNO] = @c27 ,[PDAYADJS] = @c28 ,[DBADJS] = @c29 ,[msrepl_tran_version] = @c30 where [BRANCHID] = @c1 and [RECORD_NUMBER] = @c2 and msrepl_tran_version = @c15 end else begin if not exists (select * from [CCSYSTEM] where ( [BRANCHID] = @c16 and [RECORD_NUMBER] = @c17 ) ) begin update [CCSYSTEM] set [BRANCHID] = @c16,[RECORD_NUMBER] = @c17,[TYPE] = @c18,[CURRPERIOD] = @c19,[YEAR] = @c20,[INCRTXNO] = @c21,[PDAYINCR] = @c22,[DBINCR] = @c23,[CASHTXNO] = @c24,[PDAYCASH] = @c25,[DBCASH] = @c26,[ADJSTXNO] = @c27,[PDAYADJS] = @c28,[DBADJS] = @c29,[msrepl_tran_version] = @c30 where [BRANCHID] = @c1 and [RECORD_NUMBER] = @c2 and msrepl_tran_version = @c15 end end go drop procedure [sp_MSdel_CCSYSTEM] go if exists (select * from sysobjects where type = 'P' and name = 'sp_MSdel_CCSYSTEM') drop proc [sp_MSdel_CCSYSTEM] go create procedure [sp_MSdel_CCSYSTEM] @c1 varchar(2),@c2 int,@c3 varchar(80),@c4 float,@c5 float,@c6 float,@c7 float,@c8 float,@c9 float,@c10 float,@c11 float,@c12 float,@c13 float,@c14 float,@c15 uniqueidentifier as delete [CCSYSTEM] where [BRANCHID] = @c1 and [RECORD_NUMBER] = @c2 and msrepl_tran_version = @c15 go create procedure [sp_MSdel_CCSYSTEM];2 @c1 varchar(2),@c2 int,@c3 varchar(80),@c4 float,@c5 float,@c6 float,@c7 float,@c8 float,@c9 float,@c10 float,@c11 float,@c12 float,@c13 float,@c14 float,@c15 uniqueidentifier as delete [CCSYSTEM] where [BRANCHID] = @c1 and [RECORD_NUMBER] = @c2 go DROP TABLE [conflict_Accounts_CCSYSTEM] GO CREATE TABLE [conflict_Accounts_CCSYSTEM]( [BRANCHID] varchar(2) NOT NULL ,[RECORD_NUMBER] int NOT NULL ,[TYPE] varchar(80) NULL ,[CURRPERIOD] float NULL ,[YEAR] float NULL ,[INCRTXNO] float NULL ,[PDAYINCR] float NULL ,[DBINCR] float NULL ,[CASHTXNO] float NULL ,[PDAYCASH] float NULL ,[DBCASH] float NULL ,[ADJSTXNO] float NULL ,[PDAYADJS] float NULL ,[DBADJS] float NULL ,[msrepl_tran_version] uniqueidentifier NOT NULL ,origin_datasource nvarchar(255) NULL ,conflict_type int NULL ,reason_code int NULL ,reason_text nvarchar(720) NULL ,pubid int NULL ,tranid nvarchar(40) NULL ,insertdate datetime NOT NULL ,qcfttabrowid uniqueidentifier DEFAULT NEWID() NOT NULL) GO CREATE UNIQUE INDEX [cftind_Accounts_CCSYSTEM] ON [conflict_Accounts_CCSYSTEM]( [BRANCHID], [RECORD_NUMBER], tranid, qcfttabrowid) GO ------end sch file There was also this in a .idx file: ------begin idx file SET QUOTED_IDENTIFIER ON GO ALTER TABLE [CCSYSTEM] ADD PRIMARY KEY CLUSTERED ( [BRANCHID], [RECORD_NUMBER] ) GO ------end idx file And although the bcp didn't make much sense I could see that there was only 1 line and among the random characters at the begining I could see NE which is the BRANCHID and 1 being the RECORD_NUMBER (it actually says A1!) Took me a while because I had to re-initailize the replication to get to these again. Regards
OK - it sounds like you have everything correct. Is it at all possible that you have left the original row in the central subscriber table by mistake (- sorry to ask this :))? If not, then I'm stumped. You could remove the PK constraint on the subscriber and allow the record to enter just to see if this sheds any light on the problem.... Cheers,
Paul, thanks again for the help... you where right about the 'original row' being in the subscriber table. I deleted it and restarted the agent, I got the same error but on a different table. How have I got to this point? I did get a 'General network error' on the second publisher at first could this have caused these problems? Would it be easier for me to just drop all the tables at the subscriber and start again? Regards
Yes - I'd probably restart. It'll be easier to rule out any other similar problems if this is redone from scratch and it's not really that difficult to do. Cheers, Paul Ibison
Don't see what you're looking for? Try a search.
|