Exception: New transaction is not allowed because there are other threads running

this was crazy the solution was found in the following thread

http://stackoverflow.com/questions/2113498/sqlexception-from-entity-framework-new-transaction-is-not-allowed-because-there/3902790#3902790

Reason: we cannot do savechanges while still the reader is open.

//This will fail because we are doing savechanges while the reader is open
xs= Dataservice.GetX().Where(x=>!x.Ideleted)

foreach(x in xs)
{
//do something
Savechanges()
}

//this will succed becasuse we did a tolist(which closed the reader) and then did savechanges

xs= Dataservice.GetX().Where(x=>!x.Ideleted).ToList();

foreach(x in xs)
{
//do something
Savechanges()
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: