Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Failed to enable constraints in Strongly Typed Dataset table

Hi Experts,

I created a program in VS 2008 which is used to process orders and I would like speed up this order entry process by having the users import the orders directly to the database. Once it is imported, they can open the order in the program and post it like they usually do when it is manually entered.

For orders that are imported, I am getting the "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints". I get this error when I am trying to fill a strongly typed Orderheader datatable during the posting procedure. When the order is created manually, I have no issue filling this table. I checked all the fields in the DB and the fields for the imported orders match the fields for orders that manually entered so I am not sure what is causing the error.

Can someone point me in the right direction to resolve this issue?
0
jnsimex
Asked:
jnsimex
1 Solution
 
sarabandeCommented:
a constraint can only be established if all records of the dependent table have a non-null value for the field the constraint should work on and if those values all are valid into regard of the constraint.

so check your existing records on
 - null values if it is a non-null constraint (what mostly included unique or foreign key as well)
 - duplicates in case of a unique constraint
 - invalid keys for foreign key constraints

the latter also may happen if the keys differ in case, spaces or precision (floating point numbers) or are null values.

if you can't find what is causing the error you should export the data, enable the constraint and then insert the data record by record until the error occurred.

Sara
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
If you are able to script the schema of your table you'll see which columns are not nullable and which ones has other constraints.
0
 
apeterCommented:
If you are doing your Dev/testing environment, Enable the SQL DB profiler and check what SQL Script/values are coming in when you import. This will help you to analyse further.

OrderHeader has a relation to another table like order/something like that ? then you should create order first before creating OrderHeader
0
 
jnsimexAuthor Commented:
Thank you so much for your reply. There was a trailing space in the imported key value causing the constraint error.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now