ASP.NET DataSet Error: "Failed to enable constraints. One or more rows…"

by Nate on July 3, 2007

I work with DataSets a lot in ASP.NET, so I was very surprised when I added a new query to an existing TableAdapter and got an error “Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints” from the new query. I knew that the query was fine, as I executed it with set parameters and received the expected results. I even tried setting EnforceConstraints to false on the dataset, but still no luck.

Then I found a remarkably helpful blog post on this very same error. Well, to clarify: the blog post (which was really more a plea for help than anything else) didn’t help me much, but the comments had a ton of suggested solutions. I slowly picked my way through them, one by one, working through some and skipping over others. I finally found a solution to my problem at the bottom of the page.

The schema that was returned from the suspicious query didn’t match the schema returned by the TableAdapter. The solution was to create a new TableAdapter that returned the same schema as my query. After that, everything worked as expected.

The thing is, I never received an error message when adding the new query to the TableAdapter, and the behavior doesn’t seem consistent at all, as I have several other TableAdapters that have multiple queries which return different schemas. So, I’m still looking for a *real solution (if it exists). This is one of those frustrating problems that I’d really like to get my arms around.

Anybody else dealt with this?

{ 1 comment… read it below or add one }

1 RickIsWright May 11, 2009 at 7:39 am

I have the solution. Don’t Return a Table, Fill one. Seriously. See my post athttp://www.rickiswright.com/Home/TableAdapterWhitepaper/tabid/56/Default.aspx

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: