How to: Profile Driver Performance Data (ODBC)
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.
Security 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
In Control Panel, double-click Administrative Tools and then double-click Data Sources (ODBC). Alternatively, you can invoke odbcad32.exe.
Click the User DSN, System DSN, or File DSN tab.
Click the data source for which to log performance.
Click Configure.
In the Microsoft SQL Server Configure DSN Wizard, navigate to the page with Log ODBC driver statistics to the log file.
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
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"
Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA and SQL_PERF_START to start logging performance data.
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.
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
Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA and SQL_PERF_START to start profiling performance data.
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.
Call SQLSetConnectAttr with SQL_COPT_SS_PERF_DATA and SQL_PERF_STOP to stop logging performance data.
See Also