SQL Server – Stop/Close a Server-Side Trace
This function “sp_trace_setstatus” modifies the current state of the specified trace.
Syntax
sp_trace_setstatus [ @traceid = ] trace_id , [ @status = ] status
Example
--See the Ruuning trace SELECT * FROM ::fn_trace_getinfo(NULL) -- Stop thr Running Trace EXEC sp_trace_setstatus @traceid = 1 , @status = 0 -- Delete the Running trace EXEC sp_trace_setstatus @traceid = 1 , @status = 2
Note:
0 = Stops the specified trace.
1 = Starts the specified trace.
2 = Closes the specified trace and deletes its definition from the server.