Scripting a profile trace with CHANGEABLE file name

  • Hi its only the following bit where I am struggling

    exec @rc = sp_trace_create @TraceID output, 0, N'InsertFileNameHere', @maxfilesize, @Datetime

    I would like to replace InsertFileNameHere with a @variable, but I can not get it to work.

    Please could someone help me with the syntax?

    Many thanks

  • Declare @filename nvarchar(245),

    @rc Int,

    @TraceID Int,

    @maxfilesize Int,

    @DateTime DateTime

    Set @filename = 'FilePath\FileName'

    Set @maxfilesize = 20

    Set @DateTime = DateAdd(Day, 1, GetDate())

    exec @rc = sp_trace_create @TraceID output, 0, @filename, @maxfilesize, @Datetime

    Select @TraceID as traceid

  • Ive got a stored procedure which does it; is this what you want?

    --we want the current trace folder

    declare @path nvarchar(256)

    --ie c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG

    SELECT @path = REVERSE(SUBSTRING(REVERSE(path),CHARINDEX('\',REVERSE(path)),256)) FROM sys.traces WHERE is_default = 1

    SET @path = @path + N'MyDMLtrace' --system appends .trc automatically for the filename

    --create the trace

    exec sp_trace_create @traceidout output, @maxRolloverFiles, @path, @maxfilesize, NULL

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Great help people. Many thanks

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply