Monday, March 26, 2012

ReportViewer :: Failed to enable constraints. But my statement is valid!

An error has occurred during report processing.Exception has been thrown by the target of an invocation.Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

Why do I keep getting this error, even when not using any data on the report. When I run the query in SQL server I get a resultset. However when I try to render the report I get this error.

Thanks!

I'm not using Report Services for the data I use in my reports, but when I get this error in my Report Viewer controls it's because VS carried over the primary keys from source views when I created my SQL Server table adapters.

To remedy this, I open the dataset file I'm using in my VS project and find the table adapter I'm using as my data source for the problematic report. If there are keys next to any columns (thereby marking them as primary keys in the table adapter), I right click one of the columns and select "Delete Key". I make sure all the keys are removed and then save the file and try the report again. This has fixed it every time (and every time this happened, the error never showed when I previewed the data in VS or in SQL Server itself - only when I tried to render the report from my site. Quite maddening.).

Hope this works for you, too . . .

|||

What a man!!! Worked a treat. Thanks

M

No comments:

Post a Comment