• PAH-440118 (12/2/2010)


    Thanks for this article. it was just what I needed and a feature I did not know about. I have been experimenting and it looks great however I get an error if the trace file already exists as a new one cannot be created (as you would expect). Is there a way of setting the output file name to be something that changes on each execution?

    I have tried to create a variable for the file name and concatenating to this the date but this does not seem to work either.

    Declare @SaveTo varchar(max)

    Set @Saveto = 'C:\DirName\'+ (cast(Getdate()as char))

    exec @rc = sp_trace_create @TraceID output, 2, @Saveto, @maxfilesize, @stoptime,NULL

    I get an error of ‘Procedure expects parameter '@tracefile' of type 'nvarchar(256)'.’

    Any Suggestions?

    Johan seems to have already answered your question for you. Let me know if you have any more.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning