You want to monitor the opening and closing of connections and the number of connections in the connection pool while an application is running.
Use the Windows Performance Monitor and the SQL Profiler to monitor connections and connection pooling. See Recipe 1.17 for more information on connection pooling.
The following subsections discuss monitoring connection pooling for SQL Server and ODBC .NET Framework data providers.
You can monitor SQL Server connections and connection pooling using the SQL Server Profiler or the Windows Performance Monitor as described in the following subsections.
SQL Server Profiler. To use the SQL Server Profiler to monitor connection pooling:
Start the Profiler using one of the following methods:
From Windows desktop: Start → All Programs → Microsoft SQL Server → Performance Tools → SQL Server Profiler.
From SQL Server Management Studio: Tools → SQL Server Profiler.
When the SQL Server Profiler appears, select File → New Trace.
Supply connection details and click Connect. The Trace Properties dialog box will appear.
Select the Events Selection tab of the Trace Properties dialog box.
In the Selected Events list box, ensure that the
Audit Login
andAudit Logout
events appear beneath the Security Audit node. Remove all other events from the list. Click the Run button to start the trace.The new Profiler window will display a table containing
Audit Login
events when connections are established andAudit Logout
events when connections are closed.Figure 1-22 shows the result of the trace after a database connection is opened and closed.
Windows Performance Monitor. To use the Windows Performance Monitor to monitor connection pooling:
Start Performance Monitor by selecting Start → All Programs → Administrative Tools → Performance.
Right-click the graph and select Properties from the context menu to open the System Monitor Properties dialog. Select the Graph tab and set the "Vertical scale maximum" to 2. This will make the results easier to see. Click OK to close the dialog.
Add performance counters to monitor connection pooling with one of the following methods:
Right-click the graph and select Add Counters from the pop-up menu.
Click the Add button above the graph.
Both of these actions open the Add Counters dialog shown in Figure 1-23.
In the "Performance object" drop-down list, select
SQLServer:General Statistics.
Performance counters can help tune connection pooling and troubleshoot pooling problems. To get an explanation for a counter, select the counter and click the Explain button.Select the
User Connections
counter from the list and click the Add button. Click the Close button.Figure 1-24 shows the Performance Monitor as a user connects to and disconnects from SQL Server.
To enable ODBC performance monitoring:
Open the ODBC Data Source Administrator by selecting Start → All Programs → Administrative Tools → Data Sources (ODBC) as shown in Figure 1-25.
Select the Connection Pooling tab.
Ensure that the PerfMon Enable checkbox is checked. Click OK to close the dialog.
Start Performance Monitor by selecting Start → All Programs → Administrative Tools → Performance.
Add performance counters to monitor connection pooling with one of the following methods:
Right-click the graph and select Add Counters from the pop-up menu.
Click the Add button above the graph.
Both of these actions open the Add Counters dialog shown in Figure 1-26.
In the "Performance object" drop-down list, select ODBC Connection Pooling. Table 1-7 describes the available ODBC connection pooling counters.
Table 1-7. ODBC connection pooling counters
Counter | Description |
---|---|
| Number of connections currently used by applications |
| Number of connections in the pool available for requests |
| Number of real connections per second |
| Number of connections from the pool per second |
| Hard Number of real disconnects per second |
|
Get ADO.NET 3.5 Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.