Saturday 22 December 2012

A read lock may not be acquired with the write lock, Error retrieving values from ObjectStateEntry. See inner exception for details. held in this mode.

Today , i've got this error when trying to insert record in new database.
I'm using entity framework 4.1, code first approach.

A read lock may not be acquired with the write lock,
Error retrieving values from ObjectStateEntry. See inner exception for details.

At first glance, i've thought that there's a current transaction that locks the access on the table when trying to insert a new record. So i check all actives transactions but any of them get a lock on my table.
As I use a transactionscope during the insert operation, i've removed them but the issue still not resolved.

Stop, I decided to go in deeper in the error message , that was the first thing that I had to do....

Take a close look on the InnerException.InnerException object.


Everything becomes clear now. there a violation of constraint that entity framework has detected and it raises an error when constraint has been violated.
Once those constraint have been updated, the problem is resolved !!!


No comments:

Post a Comment