Home All Groups Group Topic Archive Search About

Reading TRACE files in SQL 2000

Author
22 Aug 2006 10:46 AM
Jan
Hi all,

I would like to write a stored procedure that starts automatically when SQL
Server starts, and that logs certain events. I log to a trace file, and I
enabled the failover file option:

EXEC @rc = sp_trace_create @traceid OUTPUT
    ,@options = 2 -- TRACE_FILE_ROLLOVER
    ,@tracefile = @tracefile
    ,@maxfilesize = @maxfilesize
    ,@stoptime = NULL

Then I want to automatically read those files. This works fine with:

SELECT *
FROM ::fn_trace_gettable('D:\Microsoft SQL
Server\MSSQL\Audit\LoginAudit.trc', 1) AS T

I have written a loop to read all trace files. However, I run into trouble
when I reach the last trace file, which is still in use; I get an error:

Server: Msg 568, Level 16, State 10, Line 1
Server encountered an error 'D:\Microsoft SQL
Server\MSSQL\Audit\LoginAudit_2.trc'.

Is there a way that I can first check the 'in use' attribute of this file?

I don't run SQL 2005 with .net on this box!

Thanks,
Jan

Author
22 Aug 2006 10:40 PM
Erland Sommarskog
Jan (J**@discussions.microsoft.com) writes:
> Is there a way that I can first check the 'in use' attribute of this file?

What does fn_get_traceinfo return for property 2?


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button