Centre for Software Practice

the blog
Welcome to Centre for Software Practice Sign in | Join | Help
in Search

David Glance's Blog

Failed to Enable Constraints error in DataTables

This is an error I run into frequently and is frustrating because of course their is no indication of what constraint is being violated. So now I run through the three most frequent problems that will cause this:

  1. Having a primary key specified on the DataTable where a query can potentially return duplicates. Sometimes duplicates are unavoidable and so removing the not helpful primary key will sort this one out.
  2. Finding the columns that have been set to not allow nulls  - again, this is sometimes unavoidable and so going through all of the columns and allowing nulls will fix this.
  3. Exceeding the size of a column. This happens if you have created the DataTable and then for some reason alter the column size in the actual database table. The DataTable will not automatically update even if you alter the main query.

Occassionally I have found that nothing you do will get rid of the problem other than creating the DataTable and queries in a new DataSet (a tedious exercise).

Published Monday, 19 November 2007 1:13 PM by David.Glance
Filed under: , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

fix bad credit said:

I enjoyed this post - thank you for sharing it with everyone!

September 1, 2009 1:29 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems