question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access the state of a transaction given the NpgsqlConnection

See original GitHub issue

Is 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
rojicommented, Jun 4, 2021

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.

1reaction
rojicommented, Oct 11, 2022

Not sure if it’s “wrong”, but a simple true/false flag is insufficient to represent the three-value state.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found