Enabling Advanced Driver Tracing for the SQL Native Client ODBC Drivers

 

If you are using the SQL Native Client ODBC driver, there is built-in high performance very detailed driver tracing, here is how you use it.

#1. Create batch file to start tracing (this traces for all three versions of SQL Native Client ODBC Driver) named StartSNACTrace.cmd:

@echo off echo Starting SNAC tracing... echo {BA798F36-2325-EC5B-ECF8-76958A2AF9B5} 0xFFFFFFFF 128 SQLNCLI > providers.txt echo {A9377239-477A-DD22-6E21-75912A95FD08} 0xFFFFFFFF 128 SQLNCLI10 >> providers.txt echo {2DA81B52-908E-7DB6-EF81-76856BB47C4F} 0xFFFFFFFF 128 SQLNCLI11 >> providers.txt reg add HKLM\SOFTWARE\Microsoft\BidInterface\Loader /v :Path /t REG_SZ /d "%systemroot%\system32\msdadiag.dll" /f del /Q *.etl logman create trace -n SnacTrace -ct perf -pf providers.txt -bs 10000 -nb 10000 50000 -o SnacTrace.etl -max 100 -cnf 00 logman start -n SnacTrace echo Run StopSnacTrace.cmd to stop tracing.

Note, replace 0xFFFFFFFF with 0x00000000 to do minimum tracing.  The number 128 indicates save trace data as ANSI, which reduces by about 1/2 the space for the ETL files.

Note you MUST start the tracing before the process that uses the SQL Native Client ODBC driver starts (this is VERY IMPORTANT).   

Start the tracing then start the process that is using the SQL Native Client ODBC driver.   You can stop tracing at any time, even before the process exits.

#2. Create this batch file named StopSnacTrace.cmd to stop the tracing:

@echo off echo Stopping SNAC tracing... logman stop -n SnacTrace logman delete -n SnacTrace reg delete HKLM\SOFTWARE\Microsoft\BidInterface\Loader /v :Path /f echo SNAC tracing stopped

The above settings will create a new trace file of maximum size 100MB numbered SnacTrace_000001.etl, SnacTrace_000002.etl, etc…

#3. To process the trace files, you need to register a special mof file on the trace processing machine (you do not have to do this on the trace gathering machine)

#4. Download and register the all.mof file from "Data Access Tracing in SQL Server 2012" MSDN article (last time I checked the URL is here https://technet.microsoft.com/en-us/library/hh880086)

There is a section in this article that says "Download Sample and MOF Files". This file is named Setup.zip.

Download this file to some temporary folder and extract the files.  You will see a folder named MOF_Files, go into this folder and locate the snac*.mof files , then on the client machine where you want to do tracing,

run the following from an elevated command prompt:

C:\>mofcomp all.mof

Microsoft (R) MOF Compiler Version 6.1.7600.16385Copyright (c) Microsoft Corp. 1997-2006. All rights reserved.Parsing MOF file: all.mofMOF file has been successfully parsedStoring data in the repository...Done!

This will register all the providers so you can now see them with logman, to verify they are registered, run:

C:\>logman query providers | findstr SQL
SQLNCLI.1                                {BA798F36-2325-EC5B-ECF8-76958A2AF9B5}
SQLNCLI10.1                              {A9377239-477A-DD22-6E21-75912A95FD08}
SQLNCLI11.1                              {2DA81B52-908E-7DB6-EF81-76856BB47C4F}

You should see all 3 SNAC driver versions in the output.  You are now ready to process the traces (the *.etl files generated)

#5. To process the traces to extract the data to CSV file, use tracerpt tool (comes with Windows) or LogParser (you need to download this tool).

Run following from a command prompt:

tracerpt SnacTrace_000001.etl -of CSV -en ANSI -gmt -o SnacTrace_000001.csv

Note I find the LogParser tool (you can download from Microsoft) provides a nicer, more compact log file, try this command:

LogParser.exe "select eventnumber, eventname, timestamp, userdata into SnacTrace_000001.csv from SnacTrace_000001.etl"
-i:ETW -o:CSV -oTsFormat:"yyyy-MM-dd hh:mm:ss.n" -headers:off

This will give you a really nice looking trace file output, and LogParser is also very fast to process large traces.