两种方法的原理相同
第一种方法:
复制代码 代码如下:
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;