mssql 如何创建跟踪
详细信息请参考:F1帮助 如何创建跟踪 (Transact-SQL)
declare @datestr char(8)
set @datestr=convert(char(8),getdate(),112)
declare @filename nvarchar(256)
set @filename=@makedir+@datestr
declare @rc int
declare @TraceID int
declare @maxfilesize bigint
set @maxfilesize = 500
exec @rc = sp_trace_create @TraceID output, 0,@filename,@maxfilesize, NULL
if (@rc != 0) goto error
declare @on bit
set @on = 1
exec sp_trace_setevent @TraceID, 10, 8, @on
exec sp_trace_setevent @TraceID, 10, 16, @on
exec sp_trace_setevent @TraceID, 10, 1, @on
exec sp_trace_setevent @TraceID, 12, 11, @on
exec sp_trace_setevent @TraceID, 12, 35, @on
exec sp_trace_setevent @TraceID, 12, 12, @on
exec sp_trace_setevent @TraceID, 12, 13, @on
declare @intfilter int
declare @bigintfilter bigint
exec sp_trace_setfilter @TraceID, 1, 0, 7, N'exec sp_reset_connection'
exec sp_trace_setfilter @TraceID, 1, 0, 1, NULL
--select database_id,name from sys.databases
exec sp_trace_setfilter @TraceID, 3, 1, 0, 25 --指定数据库的DBID
exec sp_trace_setfilter @TraceID, 8, 0, 7, N'ERPSQLTEST01'
--exec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Server Profiler - 0701671f-c617-4f54-a4c5-7e3caad4d9d4'
exec sp_trace_setfilter @TraceID, 10, 1, 6, N'.Net SqlClient Data Provider' --这里只抓.NET的连接
exec sp_trace_setstatus @TraceID, 1
select TraceID=@TraceID
goto finish
error:
select ErrorCode=@rc
finish:
SELECT * INTO dba_wokfo_trctmp
FROM fn_trace_gettable('。。。.trc', default);
SELECT * FROM ::fn_trace_getinfo(default)