Print Page | Close Window

Concurrency error...but no concurrency

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2378
Printed Date: 28-Jun-2026 at 3:05am


Topic: Concurrency error...but no concurrency
Posted By: midnit
Subject: Concurrency error...but no concurrency
Date Posted: 15-Dec-2010 at 8:39am
I have a very simple entity with 4 properties, 1 key, no concurrency settings on any of the properties, the key is storegenerated.
 
While on the server I create a new entity (the one above), sets its values, save. 98% of the time (random high percentage used) it works - but sometimes it errors with "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries." and the EntityWithErrors is the entity I just created. The entitymanager has NO other data in it - just my 1 entity and again, I have no concurrency set for this entity. This entity also has no relationships to any other entities.
 
This seems random...but once this occurs any time I try to create a record for the same data...I keep getting the error. I can restart my computer and creating that one record will still error so at least THAT much is consistent.
 
I am still working on this but could use some help.



Replies:
Posted By: kimj
Date Posted: 15-Dec-2010 at 9:23am
If you're using a stored procedure for the insert or have an insert trigger that would be the first place to look.  Otherwise, I would use a profiler to see what these insert statements (even when they succeed) really look like.  If you don't have a profiler, it looks like EF Profiler will work with DevForce and they have a free trial download.
 
For example, here's an insert to the Customer table in Adventure Works:
 
exec sp_executesql N'insert [dbo].[Customer]([SalesPersonID], [TerritoryID], [CustomerType], [ModifiedDate], [rowguid])
values (null, null, @0, @1, @2)
select [CustomerID], [AccountNumber]
from [dbo].[Customer]
where @@ROWCOUNT > 0 and [CustomerID] = scope_identity()',N'@0 nchar(1),@1 datetime2(7),@2 uniqueidentifier',@0=N'S',@1='2010-12-15 00:00:00',@2='B970B5E3-DB0D-4B92-B3BA-074286704675'
 
Probably not what you'd expect, and because of the select for the store generated value you can see how an error could potentially occur.


Posted By: midnit
Date Posted: 15-Dec-2010 at 9:39am
Well I stumbled upon it as you posted. It was related to a trigger, an after insert trigger causes a legitimate error but that error is not coming back - its throwing the concurrency error.
 
Is there any way to get the actual error? Typically I do get the trigger error so I did not expect that the trigger was bombing.


Posted By: kimj
Date Posted: 15-Dec-2010 at 12:22pm

DevForce is a passive bystander with this exception, it's EF, the DB and your provider at play here.  I did a quick google but couldn't find anything helpful.  It might be worth posting a question to the EF forum ( http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/threads - http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/threads ).



Posted By: midnit
Date Posted: 16-Dec-2010 at 6:11am
Thank you for the help.



Print Page | Close Window