开发者

Creating a SQL Server Trace programmatically?

开发者 https://www.devze.com 2023-02-07 01:10 出处:网络
Anyone have any snippets for creating a SQL Server trace on the fly? I\'ve found this on MSDN but it only seems to output to the file system. What about logging it to a DB table or returning it via so

Anyone have any snippets for creating a SQL Server trace on the fly? I've found this on MSDN but it only seems to output to the file system. What about logging it to a DB table or returning it via some sort of UDF? Ideally it would be used to create a debugging tool, so it would be nice to wrap it up in something that co开发者_JAVA技巧uld be turned on and off easily.


A Server side SQL Trace not using the rowset provider can only trace to the file system.

Profiler offers the option of saving to a table but does this by consuming the rowset output and sending it back to the server which is quite inefficient.

You can easily access these server side traces though as follows and load them into a table yourself (snippet below returns the output of the default trace)

select t.* from
fn_trace_getinfo(default) i 
cross apply 
 sys.fn_trace_gettable(cast(i.value as nvarchar(4000)),DEFAULT) t
 where i.traceid=1 and i.property=2
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号