The two methods have the same principle
The first method:
Copy Code code as follows:
Procedure Sqlclosealltrack;
Const
sql = ' Declare @TID integer ' +
' Declare Trac Cursor for ' +
' SELECT Distinct traceid from:: fn_trace_getinfo (default) ' +
' Open Trac ' +
' Fetch Next from Trac into @TID ' +
' while @ @fetch_status = 0 ' +
' Begin ' +
' EXEC sp_trace_setstatus @TID, 0 ' +
' EXEC sp_trace_setstatus @TID, 2 ' +
' Fetch Next from Trac into @TID ' +
' End ' +
' Close Trac ' +
' Deallocate Trac ';
Begin
Stop all SQL Server's trackers to prevent the program from being tracked by someone else
Execsql (SQL);
End
The second method:
Copy Code code as follows:
with FAQ1 does
begin
Close;
SQL. Clear;
Sql.add (' Declare @t_count int ');
Sql.add (' Set @t_count = 1 ');
Sql.add (' while exists (SELECT *:::: Fn_trace_geteventinfo (@t_count)) ');
Sql.add (' begin ');
Sql.add (' exec sp_trace_setstatus @t_count, 0 ');
Sql.add (' Set @t_count = @t_count +1 ');
Sql.add (' End ');
Try
Execsql;
except;
End;
Close;sql. Clear;
End;
End;