all groups > sql server (alternate) > april 2005 >
You're in the

sql server (alternate)

group:

Creating a trace file with the date appended to it's name


Creating a trace file with the date appended to it's name Bill
4/28/2005 1:29:05 PM
sql server (alternate):
I'm trying to create a trace file with the file as part of it's name.
For example, I'd like to create a file called FailedLogins-20050428. So
far I haven't been able to figure out how to get the name of the file
and the date together (I'm sill very new to SQL Server and tracing).

What I've done is:
declare @rc int
declare @traceid int
declare @maxfilesize bigint
set @maxfilesize = 50
exec @rc=sp_trace_create @traceid=@traceid output, @options=0,
@tracefile=N'C:\trace\failedlogins', @maxfilesize=@maxfilesize,
@stoptime=NULL
if @rc > 0 print 'sp_trace_code failed with error code ' +
rtrim(cast(@rc as char))
else print 'traceid for the trace is ' + rtrim(cast(@traceid as char))

I can create a trace file on C drive without difficulty. I've tried
creating a file like this:
exec @rc=sp_trace_create @traceid=@traceid output, @options=0,
@tracefile=N'C:\trace\failedlogins + convert (varchar,getdate(),112',
@maxfilesize=@maxfilesize, @stoptime=NULL

But what I end up created is a file on C called
failedlogins + convert(varchar,getdate(),112).trc

I have no doubt what I want to do can be done. I just done know how to
do it.

If anyone could tell me where I'm going wrong, I'd really appreciate
it.

Thanks in advance.
Re: Creating a trace file with the date appended to it's name Greg
4/28/2005 1:42:53 PM
Hiya Bill,

Try this in Query Analyzer.. @tracefile is your variable,
@tracefile_new is the proposed fix. Take note of the @tracefile_new
output..

declare @tracefile varchar(1000),
@tracefile_new varchar(1000)

set @tracefile=N'C:\trace\failedlogins + convert
(varchar,getdate(),112'
set @tracefile_new=N'C:\trace\failedlogins_' + convert
(varchar,getdate(),112)

print @tracefile

print @tracefile_new
Re: Creating a trace file with the date appended to it's name Bill
4/29/2005 8:57:11 AM
Thanks Greg! It works great. Just the way I wanted it.
AddThis Social Bookmark Button