Page 106 - DCAP312_WEB_TECHNOLOGIES_II
P. 106
Web Technologies-II
Notes A connection pool gets created when the first connection is opened with the database.
Some Rules
To get the most out of database connection pooling, it is important to remember the following
rules:
1. If you want to pool a set of connections, all of them must have the same connection string.
2. All the connections must have the same security context. If you are using Windows
integrated security, the Windows user responsible for starting the application process is
used to determine the security context.
3. All the connections must belong to the same process.
5.7.2 Testing Connection Pooling Behavior
Now that you have some idea about what connection pooling is, you can develop a simple
application to verify the learned facts.
Begin by creating a new Windows Application and design its default form as shown Figure 5.4:
The form contains a checkbox control that governs whether or not connection pooling is enabled.
If enabled, you also can specify the minimum pool size and maximum pool size. Clicking on the
“Open a connection” button opens a database connection so that a connection pool is created.
To test the behavior of MaxPoolSize attribute, you open multiple connections with the database
at a time. The number of connections to open can be specified in the relevant textbox.
Now, go in the code window of the form class and add a helper method named
GetConnectionString() as shown below:
private string GetConnectionString()
{
SqlConnectionStringBuilder builder =
new SqlConnectionStringBuilder();
builder.DataSource = “localhost”;
builder.InitialCatalog = “northwind”;
Figure 5.4: The Default Form
100 LOVELY PROFESSIONAL UNIVERSITY