Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DELETE statement conflicted with REFERENCE constraint

Ok, here is a strange one. I have a routine that goes through and makes several deletions of old data. Ive had a few people complain about getting the error:

 System.Data.SqlClient.SqlException: The DELETE statement conflicted with
 the REFERENCE constraint

Looking at my code (im using L2S), i dont see how this is possible. But ok, lets say it is. I ask the customer to send me their DB so i can debug it some, one catch: When i hook it up to my SQL server and run the routine, i get no errors. Everything works & deletes as expected. This is a SQL 2008 Express instance on Win2008 that the DB originally comes from, and I hook it up to a full SQL 2008 instance. Are there any differences that would cause such behavior?

like image 428
Mike_G Avatar asked Oct 18 '10 21:10

Mike_G


1 Answers

Get the client to grab the sql profiler logs and check what sql is running. Compare this with the data in the tables to verify the constraint.

like image 83
Preet Sangha Avatar answered Oct 04 '22 10:10

Preet Sangha