不用事件探察器,可以用sql语句建立跟踪,将情况记录到跟踪文件中下面是一个示例,具体使用的存储过程的语法及作用说明参考sql联机帮助
-- Create a Queue
declare @rc int
declare @TraceID int
declare @maxfilesize bigint
set @maxfilesize = 5 -- Please replace the text InsertFileNameHere, with an appropriate
-- filename prefixed by a path, e.g., c:\MyFolder\MyTrace. The .trc extension
-- will be appended to the filename automatically. If you are writing from
-- remote server to local drive, please use UNC path and make sure server has
-- write access to your network shareexec @rc = sp_trace_create @TraceID output, 0, N'c:\test', @maxfilesize, NULL
if (@rc != 0) goto error-- Client side File and Table cannot be scripted-- Writing to a table is not supported through the SP's-- Set the events
declare @on bit
set @on = 1
exec sp_trace_setevent @TraceID, 12, 1, @on
exec sp_trace_setevent @TraceID, 12, 12, @on
exec sp_trace_setevent @TraceID, 12, 14, @on
-- Set the Filters
declare @intfilter int
declare @bigintfilter bigintexec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Profiler'
set @intfilter = 100
exec sp_trace_setfilter @TraceID, 22, 0, 4, @intfilterset @intfilter = 1
exec sp_trace_setfilter @TraceID, 23, 1, 0, @intfilterexec sp_trace_setfilter @TraceID, 35, 1, 6, N'pubs'
-- Set the trace status to start
exec sp_trace_setstatus @TraceID, 1-- display trace id for future references
select TraceID=@TraceID
goto finisherror:
select ErrorCode=@rcfinish:
go
-- Create a Queue
declare @rc int
declare @TraceID int
declare @maxfilesize bigint
set @maxfilesize = 5 -- Please replace the text InsertFileNameHere, with an appropriate
-- filename prefixed by a path, e.g., c:\MyFolder\MyTrace. The .trc extension
-- will be appended to the filename automatically. If you are writing from
-- remote server to local drive, please use UNC path and make sure server has
-- write access to your network shareexec @rc = sp_trace_create @TraceID output, 0, N'c:\test', @maxfilesize, NULL
if (@rc != 0) goto error-- Client side File and Table cannot be scripted-- Writing to a table is not supported through the SP's-- Set the events
declare @on bit
set @on = 1
exec sp_trace_setevent @TraceID, 12, 1, @on
exec sp_trace_setevent @TraceID, 12, 12, @on
exec sp_trace_setevent @TraceID, 12, 14, @on
-- Set the Filters
declare @intfilter int
declare @bigintfilter bigintexec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Profiler'
set @intfilter = 100
exec sp_trace_setfilter @TraceID, 22, 0, 4, @intfilterset @intfilter = 1
exec sp_trace_setfilter @TraceID, 23, 1, 0, @intfilterexec sp_trace_setfilter @TraceID, 35, 1, 6, N'pubs'
-- Set the trace status to start
exec sp_trace_setstatus @TraceID, 1-- display trace id for future references
select TraceID=@TraceID
goto finisherror:
select ErrorCode=@rcfinish:
go
不能使用Profiler的原因是因为是现场环境,要避免Profiler对DB的性能影响,而不是因为不能使用Profiler AP.还有为什么不能对含有临时表的存储过程作执行计划分析?