I have a multithread server that uses one MSSQL which each client should have access to. I wanted to use connection pooling also I am using this:
public static void DBconn()
{
SqlConnection pripojeni = new SqlConnection();
pripojeni.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=XYZ;Trusted_Connection=True;Min Pool Size=20";
}
Does the object will persist in memory (not the object itself rather than the open connections) if connection strings states “min pool”? Or will it be gone after finishing this method? Thanks
You should use a new
SqlConnectionobject for each connection, not create one in the static constructor. Connection Pooling works when each connection you create uses the same connection string (you should store it in a configuration file like web.config or app.config).Just create and open a
SqlConnectionobject each time, remember to close/dispose it at the end, and connection pooling will ensure that it re-uses existing, open connections.Hope that helps!