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

Unable to use SQLite in presence of ambient transactions #15413

Closed
mdonoughe opened this issue Apr 19, 2019 · 1 comment · Fixed by #17072
Closed

Unable to use SQLite in presence of ambient transactions #15413

mdonoughe opened this issue Apr 19, 2019 · 1 comment · Fixed by #17072
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@mdonoughe
Copy link

mdonoughe commented Apr 19, 2019

Since EntityFrameworkCore 2.1 gained support for ambient transactions with some providers, it is no longer possible to use EntiteFrameworkCore.Sqlite when ambient transactions are present.

In EntityFrameworkCore 2.0 an exception would be thrown due to a warning that ambient transactions were not supported, but if you configured your warnings it was possible to just ignore the warning and the ambient transaction, obviously not participating in the transaction.

EntityFrameworkCore 2.1 added support for ambient transactions, but not for Sqlite (#13825). The same as before, it recognizes that EntityFrameworkCore.Sqlite does not support ambient transactions, and gives a warning that can be ignored, but if you try to ignore the warning it goes on and tries to use distributed transactions anyway, leading to a NotSupportedException.

Exception message: System.NotSupportedException: Specified method is not supported.
Stack trace:
   at System.Data.Common.DbConnection.EnlistTransaction(Transaction transaction)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.HandleAmbientTransactions()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple`2 parameters)
   at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)

Steps to reproduce

https://github.com/mdonoughe/ef15413

Further technical details

EF Core version: 2.1.8, 2.2.3
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 10
IDE: Visual Studio 2017 15.9

@ajcvickers
Copy link
Contributor

Discussion from triage:

  • This is a bug; SQLite should be opted out.
  • We discussed changing to not explicitly enlist in the ambient transaction when an open connection is used with an ambient transaction that was created before the connection was opened.
    • This would align with the ADO.NET behavior. That is, it would require an explicit call to enlist in the transaction.
    • This is clean and consistent
    • However, it is a breaking change and it diverges from the EF6 behavior
    • Decision: for now we will not make this change, and just fix this as a bug.

@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview7 Jul 2, 2019
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 10, 2019
@AndriySvyryd AndriySvyryd removed their assignment Aug 10, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview9 Aug 21, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview9, 3.0.0 Nov 11, 2019
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. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants