How to: Profile Driver Performance Data (ODBC)

New: 14 April 2006

The SQLPERF structure is defined in Odbcss.h.

A complete sample is available that shows both the creation of a performance data log file and displaying performance data directly from the SQLPERF data structure. The complete sample code is in the file CreateAndDisplayPerformanceLog.cpp, which you can download from the SQL Server Downloads page on MSDN. This sample was developed using Microsoft Visual C++ 2005 and was developed for ODBC version 3.0 or later.

ms403322.security(en-US,SQL.90).gifSecurity Note:
When possible, use Windows Authentication. If Windows Authentication is not available, prompt users to enter their credentials at run time. Avoid storing credentials in a file. If you must persist credentials, you should encrypt them with the Win32 crypto API.

To log driver performance data using ODBC Administrator

  1. In Control Panel, double-click Administrative Tools and then double-click Data Sources (ODBC). Alternatively, you can invoke odbcad32.exe.

  2. Click the User DSN, System DSN, or File DSN tab.

  3. Click the data source for which to log performance.

  4. Click Configure.

  5. In the Microsoft SQL Server Configure DSN Wizard, navigate to the page with Log ODBC driver statistics to the log file.

  6. Select Log ODBC driver statistics to the log file. In the box, place the name of the file where the statistics should be logged. Optionally, click Browse to browse the file system for the statistics log.

To log driver performance data programmatically

  1. Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA_LOG and the full path and file name of the performance data log file. For example:

    "C:\\Odbcperf.log"
    
  2. Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA and SQL_PERF_START to start logging performance data.

  3. Optionally, call SQLSetConnectAttr with SQL_COPT_SS_LOG_NOW and NULL to write a tab-delimited record of performance data to the performance data log file. This can be done multiple times as the application runs.

  4. Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA and SQL_PERF_STOP to stop logging performance data.

To pull driver performance data into an application

  1. Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA and SQL_PERF_START to start profiling performance data.

  2. Call SQLGetConnectAttr with SQL_COPT_SS_PERF_DATA and the address of a pointer to a SQLPERF structure. The first such call sets the pointer to the address of a valid SQLPERF structure that contains current performance data. The driver does not continually refresh the data in the performance structure. The application must repeat the call to SQLGetConnectAttr any time it needs to refresh the structure with more current performance data.

  3. Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA and SQL_PERF_STOP to stop logging performance data.

See Also

Concepts

Profiling ODBC Driver Performance

Other Resources

Profiling ODBC Driver Performance (ODBC)

Help and Information

Getting SQL Server 2005 Assistance