Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading Error Message from Microsoft.Data.Entity.Storage.RelationalConnection.CheckForAmbientTransactions() #4147

Closed
michaelpaulus opened this issue Dec 21, 2015 · 6 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@michaelpaulus
Copy link

When using a transaction scope around EF7, I get an exception:

System.InvalidOperationException: An ambient transaction has been detected. Connections opened by Entity Framework will not be enlisted in ambient transactions. To suppress this warning call SuppressAmbientTransactionWarning() when overriding DbContext.OnConfiguring.

I see the discussion around this on issue:
#1584

and the check-in code

9195c1a

That added:

using (new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Suppress)) 

around the opening of a connection.

The following check-in that modified the RelationalConnection class fef4009 removed this check.

In my testing I am able to use a transaction scope when I call SuppressAmbientTransactionWarning() and the connection created does enlist in the ambient transaction. This is the behavior I want, but is opposite of what the error message said.

Is there something I'm missing? Is it safe to SuppressAmbientTransactionWarning() and use the transaction scope, safe meaning you are not going to change the behavior to prevent me from using the transaction scope?

Thanks.

@rowanmiller
Copy link
Contributor

@divega can you take a look at this one

@divega
Copy link
Contributor

divega commented Jan 6, 2016

I think @michaelpaulus is right that the exception message is misleading: It is not that database connection won't be auto-enlisted in ambient transactions on Open() when using EF7 (this is actually not up to us and it will continue to happen on desktop .NET where System.Transactions exists and providers, e.g. SqlClient are designed to auto-enlist). It is rather than EF7's connection and transaction management logic is not aware of System.Transactions and hence lacks the necessary logic to deal with ambient transactions, e.g. it won't know not to start a local database transaction during SaveChanges() if there is an active ambient transaction.

@rowanmiller
Copy link
Contributor

@divega to see what happens with us creating the nested transaction. If it works as expected then maybe we can just remove this exception.

@michaelpaulus
Copy link
Author

Instead of checking System.Transactions.Transaction.Current and throwing an exception, couldn't you save that the transaction exists in a local field and use that so you don't create your own transaction?

@divega
Copy link
Contributor

divega commented May 31, 2016

Assigning to @anpete who is fixing the exception message for RTM as part of the fix for #5580.

I have created #5595 to track the lack of support for System.Transactions separately.

@anpete
Copy link
Contributor

anpete commented Jun 1, 2016

Fixed.

@anpete anpete closed this as completed Jun 1, 2016
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants