Solved

Failed to enable constraints in Strongly Typed Dataset table

Posted on 2014-10-27
4
224 Views
Last Modified: 2014-11-04
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
Comment
Question by:jnsimex
4 Comments
 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points
ID: 40407944
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
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40408180
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
 
LVL 25

Expert Comment

by:apeter
ID: 40408286
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
 

Author Closing Comment

by:jnsimex
ID: 40422447
Thank you so much for your reply. There was a trailing space in the imported key value causing the constraint error.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now