a developer's notes – a semi-technical web development BLOG

September 5, 2011

“Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.”

I got an error today when I tried to fill a dataset. (dataset.Fill;)

“Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.”

There must be a value in one of the fields that is not following the table constraints. In my case, it was a field with a null value but the stored procedure that the application was calling, defined a table that restricted null values in that field. Trying running the SQL that is being called in Query Analyzer and see what kind of data you get back. One way of bypassing the contraints on the dataset is to set the EnforceConstraints property to false.

mydataset.EnforceConstraints = false;

You can do this to bypass the error or an alternative is to change the SQL constraints. In my scenario, I added a Default value of 0 (zero) on the field where the table was being defined.

CREATE TABLE myTable
myColumn1 INT DEFAULT 0
myColumn2 INT NOT NULL DEFAULT 0
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: