Dataset constrain error

E

eXavier

Hello,
we are fighting with constraint error in dataset. The dataset we use is
quite complex (about 30 tables) as well as stored procedure for returning the
data.
Now we are getting the famous excpetion:
"Failed to enable constraints. One or more rows contain values violating
non-null, unique, or foreign-key constraints."

We know what does it mean but it is difficult to track down where exactly
the problem is in data. Is there any way how to get more specific message or
detail for which constraint the error occured (like e.g. 'PK violated on
table t1') instead of this generic message?

Thanks a lot
eXavier
 
M

Miha Markic

If I remember correctly you should check DataRow.RowError property of each
row to find out which row caused the error.
 
C

Colbert Zhou [MSFT]

Hello eXavier,

We can set the Data.EnableConstraints to false before updating data back to
the data base. After that, we can check the HasErrors property for each
DataTable in the data set and then invoke the GetErrors method on the
tables reporting errors. The GetErrors returns a collection of DataRows and
you can invoke the .RowError property on the each of the error-stricken
rows to find out just exactly what the problem is.

Please see the discussion in the following link,
http://weblogs.asp.net/rosherove/archive/2004/10/03/DataSet-hell-_2D00_-_220
0_Failed-to-enable-constraints.-One-or-more-rows--contain-values_2E002E002E0
02E002200_.aspx

Let me know if you have any future questions on this and have a nice
weekend!

Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top