-
Notifications
You must be signed in to change notification settings - Fork 46
Collect a .NET Core SQL Driver Trace
BID Traces rely on the Event Tracing for Windows (ETW) infrastructure. This is what Windows drivers use. However, .NET Core apps are not targeted specifically at Windows and therefore use the .NET Event Tracing infrastructure. Fortunately, the .NET Core run-time provides the DOTNET-TRACE command to collect these traces on non-Windows operating systems.
- If you are tracing Microsoft drivers specifically for Windows: Collect a SQL Driver BID Trace
- If you are tracing Microsoft ODBC Drivers for Linux: Collect a SQL Driver BID Trace - near the bottom
- If you are tracing Microsoft JDBC Drivers: https://docs.microsoft.com/en-us/sql/connect/jdbc/tracing-driver-operation?view=sql-server-ver15
- The name of the trace event is Microsoft.Data.SqlClient.EventSource.
- You can use this in PerfView on Windows to trace .NET Core apps on Windows.
- This is also the trace name used in the examples below.
Download the dotnet tool: Install .NET on Linux distributions - .NET
e.g. for Ubuntu using apt-get:
sudo apt-get install -y dotnet-runtime-6.0
Installing dotnet-trace:
dotnet tool install --global dotnet-trace
SSH is used for the command windows.
WinSCP is used to copy the files to the Windows machine.
Download PerfView: Releases · microsoft/perfview (github.com)
- The test app is a .NET Core 5.0 application using Microsoft.Data.SqlClient 4.x. It is a self-contained distribution.
- The app name is DBCoreTest
- The app folder is dbcoretest
- The running user is Gandalf, but the trace user could be another account.
This scenario requires two ssh sessions to the Linux machine. A typical command might be:
ssh Gandalf@10.10.10.10
Gandalf@10.10.10.10's password:
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-1089-azure x86_64)
...
Gandalf@ubuntuvm:~$
Once both sessions are open ...
We have to start our test app and pause it, but something like a .NET Core web service would already be running.
cd dbcoretest
./DBCoreTest -connect "Server=SQLTest01;database=northwind;uid=xxxx;pwd=xxxx;encrypt=false" -command "Select * from customers" -wait -timeout 90
Press ENTER to begin the test:
Get the process ID and start the trace.
dotnet-trace ps
8734 DBCoreTest /home/Gandalf/dbcoretest/DBCoreTest
dotnet-trace collect –process-id 8734 --providers Microsoft.Data.SqlClient.EventSource
Press ENTER to un-pause the application. This step is only for testing a paused Console app. A service would not require this step.
##Trace Window This will show the trace status. You can terminate the trace early by CTRL+C (tracing a service) or let it run to the end (console app).
[00:00:01:03] Recording trace 1.2843 (MB)
Press <Enter> or <Ctrl+C> to exit...
Trace completed.
Once the trace is complete, copy the trace file to a Windows machine and analyze it with PerfView.
The trace file name will be similar to this: DBCoreTest_20220726_194805.nettrace