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.

Npgsql.NpgsqlOperationInProgressException: A command is already in progress:

See original GitHub issue

Npgsql.NpgsqlOperationInProgressException

I’ve updated from Npgsql 4.0.7 to 5.0.1.1 Project was in VS2017, now in VS2019

The issue

After updating Npgsql from 4.0.7 to 5.0.1.1 (as We have shifted from Visual Studio 2017 to 2019 thought, lets use the latest version) without changing any code Npgsql has started giving the exception. Npgsql.NpgsqlOperationInProgressException: A command is already in progress.

In previous version 4.0.7 it was working absolutely fine. What we were doing is using the same connection to perform multiple commands (sequentially / after first command completed). But this should not be the case for the connection even if I am performing multiple commands using separate Npgsql.Command A single connection should allow multiple commands as it was allowing till 4.0.7

Exception message: Npgsql.NpgsqlOperationInProgressException: A command is already in progress
Stack trace:

Further technical details

Npgsql version: 5.0.1.1 PostgreSQL version: 13.1 Operating system: Windows 10 Pro

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Feb 9, 2021

Npgsql 4.0.7 didn’t support multiple commands on the same connection either.

Some comments on your code above:

  • Your outer query selects all Booth_Codes from tbl_Booth, and then the inner one (which causes the exception) selects… the same ID again - I can’t see how that makes sense. You already have the booth_code.
  • In many cases, a single query can be done to fetch all data, with a JOIN, UNION or similar.
  • If you’re sure you need two queries, you can load the results of the first into memory, close the first reader, and then execute the second command.
  • Finally, you can use two connections - Npgsql’s connection pool ensures that this isn’t too bad. But it still requires twice the number of connections, so make sure you really need it.

Am closing this as there’s nothing to do on the Npgsql side. I’d recommend thinking about what exactly you’re trying to do, and writing the database code more efficiently as a function of that.

0reactions
destifocommented, Jun 28, 2023

and make sure to convert IQueriable to List, working with the elements in IQueriable will cause this issue as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - A Command Is Already In Progress
Npgsql.NpgsqlOperationInProgressException: A command is already in progress: [My Query Here]. I have my Program Class Set up as such:
Read more >
EF Core - PostgreSql - A command is already in progress
A command is already in progress: SELECT o.id, o.datum_kreiranja, ... Boolean attemptPgCancellation) at Npgsql.NpgsqlCommand.
Read more >
Class NpgsqlOperationInProgressException
Thrown when trying to use a connection that is already busy performing some other ... public NpgsqlOperationInProgressException(NpgsqlCommand command) ...
Read more >
Thread: PostgreSQL: A command is already in progress in ...
net application. This application is supported by SQL and Oracle currently. To support the application in PostgreSQL (11), We have used Npgsql ......
Read more >
"A command is already in progress" when 2 quick requests
Not if it's an issue with the underlying Npgsql provider, are you using Postgres? Is the Exception StackTrace always the same? I.e. thrown...
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