ASP.net - Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints (RDLC Report)

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

 

 Solution


Question
1)

I had this error and it wasn't related with the DB constrains (at least in my case). I have an .xsd file with a GetRecord query that returns a group of records. One of the columns of that table was "nvarchar(512)" and in the middle of the project I needed to changed it to "nvarchar(MAX)".

Everything worked fine until the user entered more than 512 on that field and we begin to get the famous error message "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."

Solution:  Check all the MaxLength property of the columns in your DataTable.

The column that I changed from "nvarchar(512)" to "nvarchar(MAX)" still had the 512 value on the MaxLength property so I changed to "-1" and it works!!.



changed a field length in the db and it no longer matched the dataset.