I need to write a program which can collect SQL Server trace logs from C code. There seem to be a couple methods to do this:
- Using the most common SQL trace method where trace files are mapped to tables via stored procedures. This trace log can then be collected using SQL/ODBC. Problem with this is that trace files are rotated and limited in size. While the trace is collected it might be possible that the trace file is swapped and not all events are gathered. Second, these stored procedures will be removed in future versions, so it does not seem to be a good idea to build upon.
- The recommended way is using Extended Events instead. This supports ETW and file targets, but the setup seems to be more complex on the server side and not all SQL Server versions seem to support this.
- There is also SMO but this does not provide a C API.
So what's the recommended way to properly collect SQL Server trace logs?