I am aware of this post: Postgres Npgsql Connection Pooling But it hasn't completely solved my issue.
I conceptually understand how connection pools work but I am struggling to understand how to apply them in my .NET app using Npgsql.
Here is what I am currently doing:
NpgsqlConnectionStringBuilder cb ... // build command and set properties
cb.Pool = True // set pool setting to True and set max pool
NpgsqlConnection conn = new NpgsqlConnection(cb.ConnectionString)
public void thread1()
NpgsqlCommand cmd = new NpgsqlCommand(conn)
cmd.Connection.Open()
// code
cmd.ExecuteNonQuery
cmd.Connection.Close()
public void thread2() {
//... same thing
}
From what I understand whenever I make the new command I am actually just taking the same connection from the connection pool. I don't understand how to make use of the rest of the connection pool by only making one NpgsqlConnection object.
What happens when I do NpgsqlConnection.Open() (aka conn.Open()) vs cmd.Connection.Open()?
I feel there is something basic I am not understanding.