Friday, 30 August 2013

Database error after DeleteObject(...) / SaveChanges()

Database error after DeleteObject(...) / SaveChanges()

Context: web application / ASP.NET 4.0 / EF 4.0 / MSSQLEXPRESS2012
I'm trying to do a simple delete as follows:
if (someObject != null)
{
if (!context.IsAttached(someObject))
context.SomeObjects.Attach(someObject);
context.DeleteObject(someObject);
context.SaveChanges();
}
The code executes without problem and SaveChanges returns the expected
number of rows. But when I try to read the table afterwards it times out
(this happens in mssms as well as in code).
It also seems to corrupt other processes, returning '8501 MSDTC on server
is unavailable' and "No process is on the other end of the pipe" on
subsequent site access. Which of the three errors happens in the
application seems somewhat random, but the timeout in mssms always
happens.
Inserts and updates on the same table execute without problem.
Apart from reading through a zillion posts, I tried wrapping it in
try/catch and transaction with SaveChanges(false) and manual
AcceptAllChanges; the debugger shows the correct object just before delete
- everything appears normal until table read or accessing another page.
I'm not sure where best to look next - any ideas are greatly appreaciated!

No comments:

Post a Comment