Hi,
I am trying to use TransactionScope together with EFCore but I am getting this error:
System.InvalidOperationException : Cannot enlist local transaction, because current global transaction already contains distributed transactions.
Stack Trace:
DbConnectionClosed.Open(DbConnectionBase outerConnection)
DbConnectionBase.i()
DbConnectionBase.Open()
SQLiteConnection.Open()
da.a(DbConnection A_0)
da.b(DbConnection A_0)
ab.a(SQLiteConnection A_0)
s.a()
s.a5(DbCommandBase A_0)
cz.CreateDbCommand()
RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
Enumerator.InitializeReader(Enumerator enumerator)
<>c.<MoveNext>b__21_0(DbContext _, Enumerator enumerator)
NonRetryingExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
Enumerator.MoveNext()
Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
lambda_method75(Closure, QueryContext)
QueryCompiler.Execute[TResult](Expression query)
EntityQueryProvider.Execute[TResult](Expression expression)
Sample code:
using (var scope = new TransactionScope())
{
using var dbContext = new ApplicationDbContext(
this.DbOptionsFactory.GetDbContextOptionsForTestDb<ApplicationDbContext>())
var dbItem = dbContext.Set<Entity>()
.SingleOrDefault();
}
the connection string that I use has the following properties:
connectionBuilder.Enlist = true;
connectionBuilder.DateTimeFormat = SQLiteDateFormats.ISO8601;
connectionBuilder.Pooling = true;
connectionBuilder.JournalMode = JournalMode.WAL;
Trying to figure this out I found out that if I get the SQLiteConnection using dbContext.Database.GetSQLiteConnection() I can call EnlistTransaction(Transaction.Current) without any issue but if I use dbContext.Database.GetDbConnection() it gives me the same exception.
Using SQLiteConnection and SQLiteCommand inside a TransactionScope also seems to work just fine.
Could there be a bug inside Devart.Data.SQLite.EFCore or I am just missing something?
Thank you,
Paul