background trace keeps getting stopped

  • I used profiler to create a trace sp:

    USE [admin]

    GO

    /****** Object: StoredProcedure [dbo].[sqltrace2] Script Date: 04/23/2009 09:13:19 ******/

    SET ANSI_NULLS OFF

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    ALTER PROCEDURE [dbo].[sqltrace2] as

    /****************************************************/

    /* Created by: SQL Server Profiler 2005 */

    /* Date: 04/20/2009 12:55:48 AM */

    /****************************************************/

    -- Create a Queue

    declare @rc int

    declare @TraceID int

    declare @maxfilesize bigint

    set @maxfilesize = 5

    -- Please replace the text InsertFileNameHere, with an appropriate

    -- filename prefixed by a path, e.g., c:\MyFolder\MyTrace. The .trc extension

    -- will be appended to the filename automatically. If you are writing from

    -- remote server to local drive, please use UNC path and make sure server has

    -- write access to your network share

    exec @rc = sp_trace_create @TraceID output, 0, N'd:\jobs\duration', @maxfilesize, NULL

    if (@rc != 0) goto error

    -- Client side File and Table cannot be scripted

    -- Set the events

    declare @on bit

    set @on = 1

    exec sp_trace_setevent @TraceID, 17, 12, @on

    exec sp_trace_setevent @TraceID, 17, 1, @on

    exec sp_trace_setevent @TraceID, 17, 9, @on

    exec sp_trace_setevent @TraceID, 17, 6, @on

    exec sp_trace_setevent @TraceID, 17, 10, @on

    exec sp_trace_setevent @TraceID, 17, 14, @on

    exec sp_trace_setevent @TraceID, 17, 11, @on

    exec sp_trace_setevent @TraceID, 10, 15, @on

    exec sp_trace_setevent @TraceID, 10, 16, @on

    exec sp_trace_setevent @TraceID, 10, 9, @on

    exec sp_trace_setevent @TraceID, 10, 17, @on

    exec sp_trace_setevent @TraceID, 10, 2, @on

    exec sp_trace_setevent @TraceID, 10, 10, @on

    exec sp_trace_setevent @TraceID, 10, 18, @on

    exec sp_trace_setevent @TraceID, 10, 11, @on

    exec sp_trace_setevent @TraceID, 10, 12, @on

    exec sp_trace_setevent @TraceID, 10, 13, @on

    exec sp_trace_setevent @TraceID, 10, 6, @on

    exec sp_trace_setevent @TraceID, 10, 14, @on

    exec sp_trace_setevent @TraceID, 12, 15, @on

    exec sp_trace_setevent @TraceID, 12, 16, @on

    exec sp_trace_setevent @TraceID, 12, 1, @on

    exec sp_trace_setevent @TraceID, 12, 9, @on

    exec sp_trace_setevent @TraceID, 12, 17, @on

    exec sp_trace_setevent @TraceID, 12, 6, @on

    exec sp_trace_setevent @TraceID, 12, 10, @on

    exec sp_trace_setevent @TraceID, 12, 14, @on

    exec sp_trace_setevent @TraceID, 12, 18, @on

    exec sp_trace_setevent @TraceID, 12, 11, @on

    exec sp_trace_setevent @TraceID, 12, 12, @on

    exec sp_trace_setevent @TraceID, 12, 13, @on

    exec sp_trace_setevent @TraceID, 13, 12, @on

    exec sp_trace_setevent @TraceID, 13, 1, @on

    exec sp_trace_setevent @TraceID, 13, 9, @on

    exec sp_trace_setevent @TraceID, 13, 6, @on

    exec sp_trace_setevent @TraceID, 13, 10, @on

    exec sp_trace_setevent @TraceID, 13, 14, @on

    exec sp_trace_setevent @TraceID, 13, 11, @on

    -- Set the Filters

    declare @intfilter int

    declare @bigintfilter bigint

    exec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Server Profiler - de7dbb6f-9863-4951-9606-bd4faebe0f62'

    set @bigintfilter = 1000000

    exec sp_trace_setfilter @TraceID, 13, 0, 4, @bigintfilter

    --set @bigintfilter = 0

    --exec sp_trace_setfilter @TraceID, 13, 0, 1, @bigintfilter

    -- Set the trace status to start

    exec sp_trace_setstatus @TraceID, 1

    -- display trace id for future references

    select TraceID=@TraceID

    goto finish

    error:

    select ErrorCode=@rc

    finish:

    Immediately after running the sp, I do a SELECT * FROM :: fn_trace_getinfo(0) where value = 'd:\jobs\duration.trc', I can see the trace is there with id 2. I can also see the system trace 1 running.

    A few minutes later I do the same select and the trace is gone.

    My dev box had similar problems, but I am still having problems with the prod box. Both are Microsoft SQL Server 2005 - 9.00.4035.00 (X64) Nov 24 2008 16:17:31 Copyright (c) 1988-2005 Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2).

  • According to your trace’s definition, as soon as the file get to the size of 5MB, the trace will stop. Did you check if the file got to this size?

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Hi,

    Can U try replacing following line in code

    exec @rc = sp_trace_create @TraceID output, 0, N'd:\jobs\duration', @maxfilesize, NULL

    with

    exec @rc = sp_trace_create @TraceID output, 2, N'd:\jobs\duration', @maxfilesize, NULL

    and inform if there is any change in the behaviour.

  • Adi probably has the right answer. You could also query the default trace to see what is stopping the trace, like this:

    SELECT

    TE.*,

    FTG.*

    FROM

    sys.traces AS T CROSS APPLY

    sys.fn_trace_gettable(T.PATH, Default) AS FTG JOIN

    sys.trace_events AS TE ON

    FTG.EventClass = TE.trace_event_id

    WHERE

    TE.[name] = 'Audit Server Alter Trace Event' AND

    T.is_default = 1 AND

    FTG.TextData LIKE 'Exec sp_trace_setstatus__,[0,2]'

    Edit: Note that the code provided only queries the active trace file. If you want to query all the trace files you need to remove the file number from the trace path (_nnn).

  • Yes it must of grown beyond 5 mb.

    Thanks!

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

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