Monitoring Connections

Problem

You want to monitor the opening and closing of connections and the number of connections in the connection pool while an application is running.

Solution

Use the Windows Performance Monitor and the SQL Profiler to monitor connections and connection pooling. See Recipe 1.15 for more information on connection pooling.

Discussion

The following subsections discuss monitoring connection pooling for SQL Server and ODBC .NET Framework data providers.

SQL Server

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.

1.14.3.1.1 SQL Server Profiler

To use the SQL Server Profiler to monitor connection pooling:

  1. Start the Profiler using one of the following methods

    • From Windows desktop: Start All Programs Microsoft SQL Server Profiler.
    • From SQL Enterprise Manager: Tools SQL Profiler.
  2. When the SQL Server Profiler appears, select File New Trace.
  3. Supply connection details and click OK. The Trace Properties dialog box will appear.
  4. Select the Events tab of the Trace Properties dialog box.
  5. In the Selected Events list box, ensure that the Audit Login and Audit Logout events appear beneath the Security Audit node. Remove all other events from the list. Click the Run button to start the trace.
  6. The new Profiler window will display a table containing Audit Login events when connections are established and Audit Logout events when connections are closed.

1.14.3.1.2 Windows Performance Monitor

To use the Windows Performance Monitor to monitor connection pooling:

  1. Start Performance Monitor by selecting Start All Programs Administrative Tools Performance.
  2. Add performance counters to monitor connection pooling with one of the following methods:

    • Right-click the graph and select Add Counters from the popup menu.
    • Click the add button above the graph.
  3. In the Performance object drop down list, select ".NET CLR Data."

    The SQL Server .NET data provider adds performance counters that can tune connection pooling and troubleshoot pooling problems. Table 1-2 describes the counters.

Table 1-2. SQL Server .NET provider performance counters

Counter

Description

SqlClient: Current # of pooled and nonpooled connections

Current number of connections, both pooled and non-pooled

SqlClient: Current # pooled connections

Current number of pooled connections

SqlClient: Current # connection pools

Current number of connection pools

SqlClient: Peak # pooled connections

The largest number of connections in all pools since the process started

SqlClient: Total # failed connects

The total number of attempts to open a connection that have failed for any reason

  1. Select the counters to monitor from the list box and click the Add button. Click the Close button.

ODBC

To enable ODBC performance monitoring:

  1. Open the ODBC Data Source Administrator in Control Panel Administrative Tools.
  2. Select the Connection Pooling tab.
  3. Ensure that the PerfMon Enable checkbox is checked.
  4. Start Performance Monitor by selecting Start All Programs Administrative Tools Performance.
  5. Add performance counters to monitor connection pooling with one of the following methods:

    • Right-click the graph and select Add Counters from the popup menu.
    • Click the add button above the graph.
  6. In the Performance object drop down list, select ODBC Connection Pooling. Table 1-3 describes the ODBC Connection Pooling counters.

Table 1-3. ODBC connection pooling counters

Counter

Description

Connections Currently Active

Number of connections currently used by applications

Connections Currently Free

Number of connections in the pool available for requests

Connections/Sec Hard

Number of real connections per second

Connections/Sec Soft

Number of connections server from the pool per second

Disconnections/Sec Hard

Number of real disconnects per second

Disconnections/Sec Soft

Number of disconnects from the pool per second

Connecting to Data

Retrieving and Managing Data

Searching and Analyzing Data

Adding and Modifying Data

Copying and Transferring Data

Maintaining Database Integrity

Binding Data to .NET User Interfaces

Working with XML

Optimizing .NET Data Access

Enumerating and Maintaining Database Objects

Appendix A. Converting from C# to VB Syntax



ADO. NET Cookbook
ADO.NET 3.5 Cookbook (Cookbooks (OReilly))
ISBN: 0596101406
EAN: 2147483647
Year: 2002
Pages: 222
Authors: Bill Hamilton

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net