1.16. Setting Connection Pooling Options
Problem
You need to know the different connection pooling options and how you can control them.
Solution
Use the connection string to control connection pooling for the SQL Server, OLE DB .NET, Oracle, or ODBC.NET data provider.
The sample code contains a method and four event handlers:
Form.LoadCreates a
Connection, attaches an event handler to itsStateChangeevent, and sets default properties for controls on the form that are used to specify connection properties. TheUpdateConnection( )method is called to dynamically construct a connection string from the specified properties.UpdateConnectionString( )This method dynamically constructs a connection string from the connection string properties specified by the user in text boxes on the form. This method is called to update the connection string when the user changes the value of any of the controls used to specify connection string properties.
- Open
Button.Click Opens the
Connectionthat is based on the connection string constructed in theUpdateConnectionString( )method.- Close
Button.Click Closes the connection string.
Connection.StateChangeDisplays original and current state information about the connection when its state changes.
The C# code is shown in Example 1-11.
Example 1-11. File: ConnectionPoolingOptionsForm.cs
// Namespaces, variables, and constants using System; using System.Configuration; using System.Windows.Forms; using System.Data; using System.Data.SqlClient; private SqlConnection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access