473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cannot insert duplicate key

1
Hello,

A try:
I have got an application which runs smoothly under Windows 2003 server with SQLserver 2005. No problems at all...
The database is installed on the same server as the application.

We are working on redundancy, so we have installed this application under VMWare. This VMWare is running at a dedicated VMWare hardware.
In the VMWare, the rest is (or should be) similar: windows 2003 server, MSSQL server 2005, the application...
The application is inserting new pallet in a databases. A new pallet is introduced by 2 messages:
Message 1: SSCC, pallet ID, and inserts details like product
Message 2: SSCC, pallet ID, inserts details like weight
SSCC and palletID should be both unique.
The order in which the messages arrive is not important. I have tested this..

When message 1 arrives, it inserts the record and message 2 add's information.
And Vice versa...
message 1 is send via xml files, transferred internally to MSqueue and inserted by the application in MSSQL
message 1 is send via MSqueue, transferred internally to MSqueue and inserted by the application in MSSQL

We have only one entry point, so new pallets are coming after each other with a delay of 30s.


However (otherwise I wasn't posting here :-) ), there is "sometimes" a problem.
It runs smoothly for say a 100 pallets, and suddenly I receive this message for a new pallet...

We have been searching and testing for some weeks now, but we still haven't found any clue. Does anybody have any idea what can cause this?

-----------------------------------------------------
WMSImportConsumer(CDMSImportConsumer): Error 'Violation of UNIQUE KEY constraint 'UQ__whStorageUnit__6BCEF5F8'. Cannot insert duplicate key in object 'dbo.whStorageUnit'' when attempting to execute stored proc { call [sp_InsertwhStorageUnit](?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) } Line: 3 Column: 0-Message: <?xml version="1.0" encoding="ISO-8859-1"?>
<comtec Version="1.0"><StorageUnit><ScanCode>3541332137009 30275</ScanCode><StorageUnitID>176167</StorageUnitID><ProductCode>05410003242225</ProductCode><ProductDate>2008-10-12</ProductDate><ProductQuantity>56</ProductQuantity><StorageUnitKind>Full</StorageUnitKind><Indicator>A</Indicator></StorageUnit></comtec>
.

-----------------------------------------------------

and the stored procedure is:
Expand|Select|Wrap|Line Numbers
  1. set ANSI_NULLS ON
  2. set QUOTED_IDENTIFIER ON
  3. GO
  4. ALTER procedure [dbo].[sp_InsertwhStorageUnit] (
  5.   @whStorageUnitCode character varying(40),
  6.   @whStorageUnitScanCode character varying(80),
  7.   @id_whStorageUnitKind smallint,
  8.   @whProductCode character varying(40),
  9.   @whProductDate datetime,
  10.   @whProductQuantity integer,
  11.   @whProductIndicator character varying(40),
  12.   @whProductBatchCode character varying(40),
  13.   @whStorageUnitWidth integer,
  14.   @whStorageUnitLength integer,
  15.   @whStorageUnitHeight integer,
  16.   @whStorageUnitWeight integer,
  17.   @id_whStorageUnit integer output) as
  18. set xact_abort on
  19.   insert into [whStorageUnit]
  20.     ([whStorageUnitCode], [whStorageUnitScanCode], [id_whStorageUnitKind], [whProductCode], [whProductDate], [whProductQuantity], [whProductIndicator], [whProductBatchCode], [whStorageUnitWidth], [whStorageUnitLength], [whStorageUnitHeight], [whStorageUnitWeight])
  21.   values
  22.     (@whStorageUnitCode, @whStorageUnitScanCode, @id_whStorageUnitKind, @whProductCode, @whProductDate, @whProductQuantity, @whProductIndicator, @whProductBatchCode, @whStorageUnitWidth, @whStorageUnitLength, @whStorageUnitHeight, @whStorageUnitWeight)
  23.   set nocount on
  24.   select @id_whStorageUnit = @@identity
Jan 18 '08 #1
1 2866
ck9663
2,878 Expert 2GB
Hello,
...........................
...................
set nocount on
select @id_whStorageUnit = @@identity
1. check your primary key
2. check the value of those fields that you're inserting
3. check if those values are already existing in db.
4. resolve if you really need to insert duplicate record (you might need a diffirent eky) or analyze your input...
5. most importantly, use the code tag when posting ;)

-- CK
Jan 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Caroline | last post by:
I want to add the content of a table into another I tried to copy all fields, except the primary key: INSERT INTO table2 (field2, field3, field4, ...) SELECT field2, field3, field4, ... FROM ...
11
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
8
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day,...
3
by: Hai Nguyen | last post by:
Hi all I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field (PR) (PR) ID Project Ans 1 2 a 1 ...
2
by: mivey4 | last post by:
Okay I have 2 tables: Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes) Table B - holds a distinct list of current serial numbers...
3
by: Ashutosh Jha | last post by:
I have to Insert records through select record from a table with group by clause within a store procedure. but when i am executing the procedure, It is showing error" Violation of PRIMARY KEY...
6
by: Dave | last post by:
I really don't like the users getting an unhandled expception page, and I'm still to new with ASP.Net and C#. So please accept my appology for the 2 part question. SqlException (0x80131904) ...
2
by: nehaneha | last post by:
Violation of UNIQUE KEY constraint 'IX_User'. Cannot insert duplicate key in object 'dbo.User'.
1
by: rdsandy | last post by:
Hi, I have a table Risk, a table Mitigation and a table RiskArchive. I am taking the RiskID, Criticality and MitigationPlan fields from Risk, and MitigationActionID from Mitigation and inserting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.