skip to main content
Using the ADO.NET Client : Using Connection Pooling : Creating a Connection Pool
 

Creating a Connection Pool

Each connection pool is associated with a specific connection string. By default, the connection pool is created when the first connection with a unique connection string connects to the database. The pool is populated with connections up to the minimum pool size. Additional connections can be added until the pool reaches the maximum pool size.
The pool remains active as long as any connections remain open, either in the pool or used by an application with a reference to a Connection object that has an open connection.
If a new connection is opened and the connection string does not exactly match an existing pool, a new pool must be created. By using the same connection string, you can enhance the performance and scalability of your application.
In the following C# code fragment, three new OpenAccessConnection objects are created, but only two connection pools are required to manage them. Note that the first and second connection strings differ only by the value assigned for User ID and Password, and by the value of the Min Pool Size option.
OpenAccessConnection conn1 = new OpenAccessConnection();
conn.ConnectionString = "Host=Accounting;User ID=john;password=beach;
Database=test;Min Pool Size=50";
conn1.Open();
// Pool A is created and filled with connections to
// the minimum pool size.
 
OpenAccessConnection conn2 = new OpenAccessConnection();
conn.ConnectionString = "Host=Accounting;User ID=mary;password=jtb30cnc
Database=test;Min Pool Size=100";
conn2.Open();
// Pool B is created because the connection strings differ.
OpenAccessConnection conn3 = new OpenAccessConnection();
conn.ConnectionString = "Host=Accounting;User ID=john;password=beach;
Database=test;Min Pool Size=50";
conn3.Open();
// Conn3 is assigned an existing connection that was
// created in Pool A when the pool was created for Conn1