I am using Npgsql to access PostgreSQL through .NET. I am worried about the correct way to make connections to the database, because, in my opinion, this is an expensive operation to open a connection and then close it every time I want to perform some transaction.
So here is a general idea:
public class PostgreSQL { private NpgsqlConnection conn;
As you can see above, I have one connection for an instance of the PostgreSQL class.
My question is :
Is this approach right? Or do I need to open and close the connection every time I want to complete a transaction - open and close as soon as possible?
If I have to open and close connections every time - should I write a queue that would limit the number of parallel connections? Or PostgreSQL will handle this on its own - and, theoretically, I can open 200 connections, and everything will be fine.
Please share your experience with me ^^
EDIT: I will run 100-200 queries per second.
source share