Back to Blog
Database deadlock exception6/29/2023 ![]() ![]() With a serializable isolation level both client A and client B take a shared lock for the duration of the transaction on the record when the SELECT statement is run. and a subsequent UPDATE for the SaveChanges() call. This is due to the EF code generating two SQL statements: a SELECT for the line: var test = db.customer_table.Where(x => x.id = 38).FirstOrDefault() This is so confusing, what linq have done in behind making Transaction working inconsistent behavior? Var test = db.Database.ExecuteSqlCommand("Update customer_table set bank_holder_name = 'CLIENT XXXXX' where pu_id = 38") <= Client B is stop here and proceed after Client A is completedįinally, the transaction is working with code above (not linq function). I edited my code as below: using (myEntities db = new myEntities ()) Thus, I suspected this might caused by linq (incorrect row/ table lock) This is not what I expected where Client B should wait and not allowed to query any data about row id=38, but somehow it can proceed until SaveChanges and throws an error in the end. After CLIENT A finish commit, here will throw *Deadlock found error*" Test.bank_holder_name = "CLIENT NAME XXXX" ĭb.SaveChanges() <= CLIENT B stop here while client A still in progress. Var test = db.customer_table.Where(x => x.id = 38).FirstOrDefault() Client B needs to wait for Client A to commit his updatesīoth Client A
0 Comments
Read More
Leave a Reply. |