Error with Npgsql: "The connection pool has been exhausted, either raise MaxPoolSize (currently 100) or Timeout (currently 15 seconds)"

This is really just a wild guess, but at [1,2], I discovered the asynchronous variants OpenAsync() and CloseAsync(). Maybe using them will improve the runtime behavior right away, specifically when it comes to proper cleanup of resources.

On the other hand, [3] also has an interesting discussion about whether to favor Dispose() over Close(). In this case, you should probably also use the asynchronous variant DisposeAsync().

[1] https://github.com/npgsql/npgsql/blob/v5.0.7/src/Npgsql/NpgsqlConnection.cs#L143-L151
[2] https://github.com/npgsql/npgsql/blob/v5.0.7/src/Npgsql/NpgsqlConnection.cs#L683-L695
[3] c# - Why does this `using` block not release the database connection? - Stack Overflow

1 Like