Stop SQL Server trace using SQL command

By | January 15, 2009

Today I started SQL Profiler and paused it. After some time, none of the buttons were enabled. I can neither resume nor stop the trace. Here are the sql commands that I finally found to stop the trace.

1) Get the trace id

SELECT * FROM ::fn_trace_getinfo(default) WHERE property = 2;

2) Stop trace

DECLARE @TraceID int
SET @TraceID = ?
EXEC sp_trace_setstatus @TraceID, 0
EXEC sp_trace_setstatus @TraceID, 2

Vishal Monpara is a full stack Solution Developer/Architect with 13 years of experience primarily using Microsoft stack. He is currently working in Retail industry and moving 1’s and 0’s from geographically dispersed hard disks to geographically dispersed user leveraging geographically dispersed team members.

5 thoughts on “Stop SQL Server trace using SQL command

  1. Hestabit Technologies

    I used this code and it worked perfectly

Leave a Reply

Your email address will not be published. Required fields are marked *