-
Notifications
You must be signed in to change notification settings - Fork 819
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
"Nested/Concurrent transactions aren't supported" while using TransactionScope #731
Comments
I assume the problem lies in /src/Npgsql/NpgsqlPromotableSinglePhaseNotification.cs, in the |
The problem only occurs within a
I've downloaded the source code and debugged through it but I can't seem to find an equivalent in Npgsql code of the currently enlisted transaction of a connection (which is |
The error only occurs when I create a new DbContext instance with passing an already opened NpgsqlConnection. (I can't use fixed app.config configuration because the user must be able to set the connection data from a GUI form. And I can't just pass a connection string because there can be multiple providers and a connection string can't specify the provider.) If I do pass a prepared connection that is still closed, everything works fine. Using app.config-defined connection strings also doesn't trigger the error. The other ADO.NET providers show inconsistent behaviour about this: Some require a connection that is already open, all (except Npgsql) accept a connection this is already open. |
Thanks for reporting this, we do have some issues with TransactionScopes and distributed transactions, and plan on a serious look at all this for Npgsql 3.1. I'll try to look at your specific issue before then though (hopefully we can do a simple fix for this in 3.0.x). |
Using Considering such a major failure of the .NET Framework-recommended way of handling transactions, I have now modified my database layer back to using more traditional and comprehensible |
@dg9ngf, I know that there are some issues with TransactionScope in Npgsql and I understand the frustration, but it's definitely not supposed to be that broken. Can you take a look at the SystemTransactionTests, especially at Rollback which demonstrates a working rolled-back TransactionScope? I'd definitely be interested in precise bug scenarios which we could work to fix. Also, are you seeing broken TransactionScope behavior with other database providers? Can you provide a bit more details? |
@ygoe, am finally getting around to work on System.Transactions support - am pretty much rewriting the whole thing to be safer and simpler. I've included the check for enlisting on the same transaction twice (return and do nothing). If you can help test the upcoming 3.2, you should be able to grab recent 3.2 CI nugets from the unstable feed, or you can wait until a beta is released (hopefully not too long from now). |
@jakubprusak, TransactionScope is part of .NET's System.Transactions. Support for System.Transactions was completely rewritten in Npgsql 3.2, so any problems with using TransactionScope (such as this issue) should have gone away. Are you encountering some problem, or this a question? |
Hi @roji We try to use that using libraries like: ` private IDisposable dbContextScope;
` |
@jakubprusak, I can see your workaround, but what's missing is of course the problem itself - the exception and stack trace... Could you please open a new issue with all the required details? |
yes, I can open, but there is no exception from code side. |
@jakubprusak did you specify |
@roji StackTrace from test:
|
I had the voiding TransactionScope issue with EntityFramework6.Npgsql 3.1.1 and Npgsql 3.1.2. When i add enlist=true to connection string, it started to give "The maximum number of enlistments for the specified transaction has been reached" error. After i update Npgsql package to v3.2.1 TransactionScope worked (if you do not specify enlist=true on connection string it still voids to transactionscope) What does the enlist=true mean? if i do not use transaction scope with enlist=true does it effect behaviour? |
@mgulden I'm not sure what you mean by "voiding TransactionScope". As of 3.2, you still need to enlist in TransactionScope by either adding It's not surprising that updating 3.2.1 resolved your issue - support was totally rewritten and several bugs were presumably fixed. It's good to hear it helped. |
yes, definitely helped, thank you. |
Hi, After that i receive an error when i try to create an entity inside the TransactionScope. (in my connection string Enlist setted to true) The error text : Nested/Concurrent transactions aren't supported P.S : Same code was working with EF6 Microsoft.EntityFrameworkCore => v1.1.2 I have a base class like this; protected async Task CommonOperationWithTransaction(Func<Task> func, BusinessBaseRequest businessBaseRequest) and stacktrace konum: Npgsql.NpgsqlConnection.BeginTransaction(IsolationLevel level) |
Sometimes, when using nested
TransactionScope
s (none of which was aborted) and Entity Framework, I repeatedly get the error "Nested/Concurrent transactions aren't supported." of type NotSupportedException, inner exception of "The underlying provider failed on EnlistTransaction.", EntityException.For a simple
myContext.MyEntities.AsNoTracking().FirstOrDefault()
the stack trace is this:The same code works perfectly with SQL Server. It is reproducible 100 % for me.
I've seen this kind of error message before when I was still using
DbTransactions
when I wanted to enlist a connection with the same ambient transaction more than once. Again, this worked perfectly with SQL Server and resulted in the same error message with Npgsql. It should probably check whether the same transaction is assigned and ignore the call instead of acting as if it were different transactions.PS: The same application code runs fine with ADO.NET providers for SQL Server, SQLite, MySQL, and Oracle.
The text was updated successfully, but these errors were encountered: