The two methods work in the same way.
Method 1:
Copy codeThe Code is as follows:
Procedure SQLCloseAllTrack;
Const
SQL = 'Clare @ TID integer '+
'Descare 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' +
'Destlocate trac ';
Begin
// Stop all trackers to prevent programs from being tracked by others
ExecSql (SQL );
End;
Method 2:
Copy codeThe Code is as follows:
With faq1 do
Begin
Close;
SQL. Clear;
SQL. add ('Clare @ t_count int ');
SQL. add ('set @ t_count = 1 ');
SQL. add ('while exists (SELECT * FROM: 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;