Open Abrissirba opened 3 weeks ago
Came one step forward here, I guess this might not be a EF6 issue but I am thankfull if you are able to point me in any direction going forward.
It seems like closing and opening an existing connection makes the transaction "unenlist" from the transaction.
The ADO.NET example above that threw an exception no longer throw if the connection is closed, the connection holding the transaction killed, and then opened again.
Digging in EF6 it looks like this is what EF does, that will say opening and closing the connection.
{
var conn2 = new SqlConnection(connectionString);
conn2.Open();
conn2.Close();
// KILL THE SESSION THAT HOLDS THE is_local TRANSACTION HERE
conn2.Open();
var cmd2 = conn2.CreateCommand();
cmd2.CommandText = $"Update Prize set Name = 'Test' where PrizeId = '8892372A-8E0D-4FDA-AE6B-00496C212545'";
_ = await cmd2.ExecuteNonQueryAsync();
}
Created an issue in SqlClient instead, so this issue can probably be closed.
Ask a question
We have a problem where we are a bit stuck and need all the help we can get to pinpoint why it is happening. There is quite a lot of components in play so it is a bit difficult to set up and explain but I will try my best.
We are using TransactionScope to make sure that all changes made to the database will be made in one transaction. There will be multiple connections open, to the same db, at the same time which will elevate the transaction to DTC. Since we use Azure SQL this will be an Elastic Transaction (from what I understand)
This works as expected in most scenarios. If an error occur, the transaction scope is disposed and not changes will be commited to the Database.
The problem occur if the connection that created the transaction dies for some reason. For us this happend because of a timeout in azure that killed the connection after 30 minutes. We are aware that you should not keep transactions going on for so long and have made improvements that will make this scenario less likely. However, connections might die for other reasons making us continue to investigate this issue.
The thing that happens when the first connection dies, subsequantly queries made by EF will save the changes to the database even though the transaction died.
If we do the same but with ADO.NET we get an exception about the transaction no longer work.
Here is an example.
When looking at the transactions with the sql query it is like the transaction is killed by EF somehow. It just disappears after SaveChanges.
So what we are currently trying to figure out is why ADO.NET throws an exception, and not commiting, while EF doesn't throw any Exception and commits.