Sql-Server

使用帶參數的 sp_trace_create 時出錯

  • July 15, 2013

我在 SQL Server 2000 上執行以下 SQL:

exec sp_trace_create @options = 2,
        @tracefile = N'h:\\trace.trc',
        @filecount = 2

並收到以下錯誤,不明白為什麼:

過程需要“nvarchar(128)”類型的參數“@tracefile”

如果我像這樣傳遞所有參數:

聲明@id int

exec sp_trace_create @id output,
        @options = 2,
        @tracefile = N'h:\\trace.trc',
        @filecount = 2,
        @maxfilesize = 5,
        @stoptime = '2013-8-15'

我得到錯誤:

過程或函式 sp_trace_create 指定的參數過多。

Martin Smith 已回答https://dba.stackexchange.com/a/24728/8783

這將起作用:

DECLARE @new_trace_id INT;

EXECUTE master.dbo.sp_trace_create
 @someinteger = @new_trace_id OUTPUT,
 @someinteger = 0,
 @someinteger = N'C:\trace\TestTrace.trc';


 -- get trace status 
 SELECT * FROM ::fn_trace_getinfo(NULL)
 -- stop trace
 EXEC sp_trace_setstatus @traceid = 1 -- CHANGE THIS AS PER YOUR TRACE id
                   , @status = 0  
 go 
 -- delete trace
 EXEC sp_trace_setstatus @traceid = 1  -- CHANGE THIS AS PER YOUR TRACE id
                   , @status = 2

引用自:https://dba.stackexchange.com/questions/46397