What are the APIs used by SQL Profiler?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 09:51:22

问题


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.


回答1:


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.




回答2:


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




回答3:


This blog explains about Trae Management Object (TMO) and how to use it.

A handy profiler tool using this TMO can be found at HERE



来源:https://stackoverflow.com/questions/2719909/what-are-the-apis-used-by-sql-profiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!