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