a developer's notes – a semi-technical web development BLOG

September 5, 2011

Restore failed for Server – RESTORE HEADERONLY is terminating abnormally

Filed under: General Tips — Duy Nguyen @ 2:21 pm
Tags: , , , , ,

I found a great post on this that helped me resolve my problem:

http://dotnetguts.blogspot.com/2010/06/restore-failed-for-server-restore.html

Advertisements

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

I got an error today when I tried to fill a dataset. (dataset.Fill;)

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

There must be a value in one of the fields that is not following the table constraints. In my case, it was a field with a null value but the stored procedure that the application was calling, defined a table that restricted null values in that field. Trying running the SQL that is being called in Query Analyzer and see what kind of data you get back. One way of bypassing the contraints on the dataset is to set the EnforceConstraints property to false.

mydataset.EnforceConstraints = false;

You can do this to bypass the error or an alternative is to change the SQL constraints. In my scenario, I added a Default value of 0 (zero) on the field where the table was being defined.

CREATE TABLE myTable
myColumn1 INT DEFAULT 0
myColumn2 INT NOT NULL DEFAULT 0

Blog at WordPress.com.