Connection still idle after closing

I have a client application in C # that needs to check a table in db Postgres every 15 minutes. The problem is that I need to install this client on more or less than 200 clients, so for this I need to close the database connection after the request.

I use the .Close () method, but if I check the pg_stat_activity table on Postgres DB, I see that the connection is still open in IDLE status. How can I fix this problem? Is it possible to establish a connection?

thanks Andrea

+6
source share
1 answer

Like most ADO.NET providers, Npgsql uses the connection pool by default. When you Close() an NpgsqlConnection object, the internal object representing the actual underlying connection that uses Npgsql goes into the pool that needs to be reused, saving the extra cost of creating another one unnecessarily. (See What does “opening a connection” really mean? For more).

This is suitable for most applications, since it usually takes several times to use the connection within a second.

This doesn't suit you at all, but if you include the Pooling=false option in the connection string, it will override this default value, and Close() will really close the actual connection.

+10
source

Source: https://habr.com/ru/post/907017/


All Articles