Solved

Failed to enable constraints in Strongly Typed Dataset table

Posted on 2014-10-27
4
237 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 33

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 48

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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