I found this error on my project. Well i spent around one hour to figure out this problem. People might think that this is some silly error message.
The error message i got is “Failed to enable constraints, one or more rows contain values violating non null, unique or foreign-key constraints”.
this is caused by my stored procedure which is
SELECT e.eventid,e.event,e.eventdate,i.email,u.username
,u.firstname,u.surname,i.senttime,i.readtime,i.respond
FROM invitefriends i
inner join users u ON i.franchiseeid=u.userid
inner join events e ON i.eventid = e.eventid
WHERE i.franchiseeid is not null
and ( (@EventID IS NULL) or (e.eventid=@EventID) )
ORDER BY e.eventdate DESC
GO
Since the query is returning multiple rows with the same eventid and the primary key in my datatable is eventid then it caused the error.
There are two workaround to this problem:
Leave a Reply