Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Replication Issue. Inserting through a Trigger.


Replication Issue. Inserting through a Trigger.

Author
Message
baabhu
baabhu
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1417 Visits: 1215
Hi All,

I just setup the replication in my environment.

Table structure.

CREATE TABLE [dbo].[pwallet_tran](
[TId] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[uid] [varchar](100) NOT NULL,
[currencycode] [varchar](10) NOT NULL,
[ledgerBalance] [decimal](20, 2) NULL,
[availableBalance] [decimal](20, 2) NULL,
[lastUpdateDate] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[TId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF


CREATE TABLE [dbo].[pwallet](
[wId] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[uid] [varchar](100) NOT NULL,
[currencycode] [varchar](10) NOT NULL,
[ledgerBalance] [decimal](20, 2) NULL,
[availableBalance] [decimal](20, 2) NULL,
[lastUpdateDate] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[wId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


Trigger is used for inserting the data in pwallet_tran


ALTER TRIGGER [dbo].[trigger_wallet_history] ON [dbo].[pwallet]
FOR UPDATE
AS
INSERT INTO pwallet ([uid],[currencycode],[ledgerBalance],[availableBalance],[lastUpdateDate])
SELECT a.[uid], a.[currencycode], a.[ledgerBalance]-b.[ledgerBalance], a.[availableBalance]-b.[availableBalance], CURRENT_TIMESTAMP
FROM inserted a INNER JOIN deleted b ON a.[uid]=b.[uid];

INSERT INTO pwallet_tran ([uid],[currencycode],[ledgerBalance],[availableBalance],[lastUpdateDate])
SELECT b.[uid], b.[currencycode], b.[ledgerBalance], b.[availableBalance], CURRENT_TIMESTAMP
FROM inserted a INNER JOIN deleted b ON a.[uid]=b.[uid];

I have SQLserver 2008 R2 Enterprise edition. I setup P2P replication.

After I completed the setup I encountered the following error.

Error.
Command attempted:
if @@trancount > 0 rollback tran
(Transaction sequence number: 0x000003BF000000D8000B00000000, Command ID: 1)

Error messages:
• Explicit value must be specified for identity column in table 'pwallet_tran' 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 'pwallet_tran' 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)


Should I not use trigger to update the data for the columns used as not for replication.

Please let me know how to solve this.

Thank you very much.
deepzzzz
deepzzzz
SSC Eights!
SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)

Group: General Forum Members
Points: 885 Visits: 261
I think it is because you are trying to replicate the identity column, which is similar to insert explicit value in a identity column.
So, please check the below link may be useful..
http://www.mssqltips.com/sqlservertip/1274/change-not-for-replication-value-for-sql-server-identity-columns/

Thanks
baabhu
baabhu
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1417 Visits: 1215
Thank you very much.
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