We are using Entity Framework and running unit tests within a transaction scope. We were origianally getting the error in the title.
I have managed to isolate the problem some what.
using (TransactionScope scope1 = new TransactionScope())
{
using (TransactionScope scope2 = new TransactionScope())
{
// Here there is no code
}
using (Entities se = new Entities())
{
EntityConnection entityConnection = (EntityConnection)se.Connection;
DbConnection storeConnection = entityConnection.StoreConnection;
storeConnection.Open(); // On this line the error occurs
// Some code that runs a stored procedure
}
}
The error that we are currently getting is "The operation is not valid for the state of the transaction.."
If I remove transaction scope2, everything works fine.
If I mark scope 2 as an ambient transaction it also works fine.