Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the APIs used by SQL Profiler?

SQL Server Profiler displays a live stream of commands being executed against a SQL server instance. What are the APIs used to capture this data?

Background: I need to write a small utility (in C++) which tracks the SQL commands being issued by a separate application.

like image 209
stusmith Avatar asked Dec 22 '25 06:12

stusmith


2 Answers

Here on the API Development Team Blog is a quick C# (should be easy to convert to c++) program which connects to SQL Server and shows the text of all starting batches in real time as the requests are coming to SQL Server.

e.g. Code snippet from link

Console.WriteLine("Event : " + trace["EventClass"]);
Console.WriteLine("SPID  : " + trace["SPID"]);
Console.WriteLine("Login : " + trace["SessionLoginName"]);
Console.WriteLine("Object: " + trace["ObjectName"]);
Console.WriteLine("Text  : " + trace["TextData"]);

As Alex mentioned, you will need to use the TraceServer API.

like image 60
kevchadders Avatar answered Dec 24 '25 02:12

kevchadders


I don't know if this is how Profiler does it, but they are exposed via the TraceServer API.

like image 41
Alex K. Avatar answered Dec 24 '25 01:12

Alex K.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!