Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Failed to enable constraints in Strongly Typed Dataset table

Posted on 2014-10-27
4
Medium Priority
?
267 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 35

Accepted Solution

by:
sarabande earned 2000 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 52

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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