Solved

Failed to enable constraints in Strongly Typed Dataset table

Posted on 2014-10-27
4
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 34

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 51

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

635 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