Web Development

General discussion


SQL Problem

By pjsinclair ·
We are running an SQL DataBase when we try to access one of the fields we get the error message

Problem adding new Sample details : Primary Key constant PK_ordersamples': Attempt to insert duplicate key in object 'OrderSamples'.

any help would be greatly accepted

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by MadestroITSolutions In reply to SQL Problem

My friend,

This means that the column "ordersamples" has a primary key constraint, which means that this column cannot contain duplicate values.

You are trying to add a record to that table with a "ordersamples" value that already exists in the table, so either you remove the constraint (if you feel this column should accept duplicate values) or check the value you are entering.

Good Luck!

Collapse -

by MobileTech In reply to SQL Problem

pjsinclair, what this is telling you is that you have primary key located over one of the fields in the ordersamples table I am not sure which field it is but if you look in the enterprise manager,under the design table you will see a key symbol over one or more fields, these are the primary keys, you are trying to insert a new row that has the same field contents as another row in the table that has a primary key defined for it.

Collapse -

by hmertens In reply to SQL Problem

You state that your are "accessing" a database (versus "inserting", "deleting" or "updating" data). Presuming that you are NOT intending to actually add a new record or changing data...

You also state that your are "accessing a field". But are you updating a "scratch" table within a database to view entries from other tables? If so...

1) Be sure you delete previous records before refreshing the table with a new "access" effort.
2) Preferentially, if using SQL2k, make use of temporary tables. These are more flexible in managing security issues and if you set these tables to be persistent to a specific user connection they'll automatically be cleared when the user connection is released.
3) Wouldn't accessing a specific field be better achieved by a query or view or SQL2k scalar function?

Collapse -

by hmertens In reply to

One more point:

In any case, if your table MUST have duplicate field values across rows, then you must insure that the field is NOT set as a primary key and/or have a field contraint restrictring it from having duplicates.


Collapse -

by hmertens In reply to SQL Problem

Alternate solution issue; are we actually dealing with a application (user control) bound to a database? Is your problem actually based on control having an inappropiate starting value that it is trying sync back to the database prior to pointing to a specific database record (ie. you are defaulting on the first (or a random) record on start up and the control is trying to sync the record to values present on the form.

Be sure that you haven't corrupted your database with an instance of this default value and be sure when bringing up a bound control that you are pointing to an appropiate database records (typically on form initialization, but before creating instances of controls at form load).

Your question could use some more details.

Collapse -

by hmertens In reply to
Collapse -

by D_Gilmour_1978 In reply to SQL Problem

Insure you have an automatic incremeting primary key on the table.
This uniquely identifies each record as every record has to be different in a table

Collapse -

by pjsinclair In reply to SQL Problem

This question was closed by the author

Related Discussions

Related Forums