Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
When working with a DataSet object, I got this error.
“Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.”
Talk about annoying – this took me the better part of an hour and half to figure out where this error was coming from. Quite descriptive if you ask me <rolling eyes>. It’s as useful as this:
As with any bug the more information you can get on it – the better. The code I put together thanks to a tip from Roy Osherove’s Blog gets into the DataSet object to see which column is actually throwing the error.
foreach( DataTable table in dataSet.Tables)
{
if (table.HasErrors)
{
foreach ( var error in table.GetErrors())
{
if (error.HasErrors)
throw (new Exception( error.RowError));
}
}
}
This produced a much more descriptive error that allowed me to track down the problem:
Shendy.

Leave a Reply
You must be logged in to post a comment.