兩種方法的原理相同
第一種方法:
復制代碼 代碼如下:
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
//停止所有SQLSERVER的跟蹤器,以防止程序被別人跟蹤
ExecSql(sql);
end;
第二種方法:
復制代碼 代碼如下:
with faq1 do
begin
Close;
sql.Clear;
sql.add('declare @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;