Get Information on Current Traces Running
sql-server
This is just a quick informational query to save as a snippet to get some quick information on running traces, and provide the stop and close snippet quickly if you want to stop a server side trace you created.
obtain information on traces running
------------------------- obtain information on traces running -------------------------
select
trace_id = id
,is_rowset
,trace_name = reverse(left(reverse(path),
charindex('\', reverse(path),
1) - 1))
,trace_duration =
case
when stop_time is not null then 'Duration (min): ' + convert(varchar(10), datediff(minute, start_time, stop_time), 120)
else 'No duration limit'
end
,status =
case status
when 0 then 'Stopped'
when 1 then 'Running'
end
,stop_trace_command =
case
when id = 1 then 'Default Trace, No actions to take'
when t.is_rowset = 1 then 'Stop trace in profiler'
else cast('-- Stops the specified trace.
exec sp_trace_setstatus ' + cast(id as nvarchar(10)) + ', 0
-- Closes the specified trace and deletes its definition from the server.
exec sp_trace_setstatus ' + cast(id as nvarchar(10)) + ', 2' as nvarchar(max))
end
,max_size
,t.max_files
,t.is_rollover
,t.event_count
,t.dropped_event_count
,start_time
,stop_time
from
sys.traces as t