Access the state of a transaction given the NpgsqlConnection
See original GitHub issueIs there any way to get any indicator to an ongoing transaction given a NpgsqlConnection
instance such as Connector.InTransaction
? As an alternative would it at least somehow be possible to access the state of a transaction itself, such as NpgsqlTransaction.Diposed
?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Npgsql Basic Usage
ExecuteReaderAsync: execute SQL which returns a full resultset. Returns an NpgsqlDataReader which can be used to access the resultset (as in the above...
Read more >Class NpgsqlConnection | Npgsql Documentation
Initializes a new instance of NpgsqlConnection with the given connection string. ... Gets whether the current state of the connection is Open or...
Read more >Why the NpgsqlConnection is not properly closed or ...
not valid for ; ---> System.TimeoutException: Transaction Timeout --- End of inner exception stack trace --- ; 0>d.MoveNext() --- End of stack ...
Read more >PostgreSQL and C# - Working with Result Sets - Npgsql . ...
Npgsql .NET Data Provider allows you to process result sets returned by a SELECT statement (query) a PostgreSQL function (stored procedure).
Read more >SqlConnection.BeginTransaction Method
Starts a database transaction with the specified isolation level and transaction name. BeginTransaction(). Starts a database transaction.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I guess we could expose the transaction status indicator, just as the protocol delivers it to us in the ReadyForQuery message. I wouldn’t attempt to expose NpgsqlTransaction - it may not exist (if the transaction was created with raw SQL), and it really is the caller’s responsibility to track that instance.
If we do decide to do this, I think we should expose the full three values, not just a bool (so idle, in a transaction, in a failed transaction). Knowing whether the connection is in a failed transaction seems just as useful… Note that our internal enum used for representing this is probably not suitable, since it also contains an internal-only Pending value, so we may need another enum…
But I think all this should go into the backlog - we have more urgent things to do… @TwentyFourMinutes if you’re going down the wrapping route, I’d go all the way like EF Core does and wrap NpgsqlTransaction.
Not sure if it’s “wrong”, but a simple true/false flag is insufficient to represent the three-value state.