Importing SQL Server Extended Events XEL with BCP

07 Aug 2019 0 minutes to read Contributors

Extended Events

SQL Server has the ability to catch all kind of 'events' into an Extended Event File (XEL). These files are readable with C# / Powershell / SQL functions.

Reading XEL files can be a lengthy task especially when you want to do analysis on the data.

SQL Read XEL Function

SQL Server provides  a function to read XEL files: sys.fn_xe_file_target_read_file ( path, mdpath, initial_file_name, initial_offset )

That function reads files that are created by the Extended Events asynchronous file target. One event, in XML format, is returned per row.

More info here:

https://docs.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-xe-file-target-read-file-transact-sql

C# / Powershell

The function is implemented in Microsoft SQL Server libraries that are invokable by C# or Powershell:

Microsoft.SqlServer.XEvent.Linq.QueryableXEventData

Solution

We have created a powershell solution that uses this library to reads XEL files and import them via BCP into a database table.

In this article