SQL Server 2008 R2 Server Side Tracing

  • I am having issues with SQL Server Profiler. Whenever I run the profiler after a couple of minutes it hangs the application...I am pretty sure that its not a hardware issue. So I created a server side trace script and am using it to run on the server side through a sql server job...every time I run the script it runs successfully but only generates a 5mb trace file. But in the actual template before scripting it out I enabled it rollover after 50mb. Also I have even mentioned that the end time for this trace as 10:30 tonight, before scripting it out. But still it runs only for a couple of seconds and says job completed successfully.

    Any suggestions??

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

    /* Created by: SQL Server 2008 R2 Profiler */

    /* Date: 10/02/2011 09:13:01 PM */

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

    -- Create a Queue

    declare @rc int

    declare @TraceID int

    declare @maxfilesize bigint

    declare @DateTime datetime

    set @DateTime = '2011-10-03 22:09:28.000'

    set @maxfilesize = 50000

    -- 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'E:\Trace\Trace', @maxfilesize, @Datetime

    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, 122, 1, @on

    exec sp_trace_setevent @TraceID, 122, 25, @on

    exec sp_trace_setevent @TraceID, 122, 2, @on

    exec sp_trace_setevent @TraceID, 122, 10, @on

    exec sp_trace_setevent @TraceID, 122, 14, @on

    exec sp_trace_setevent @TraceID, 122, 26, @on

    exec sp_trace_setevent @TraceID, 122, 34, @on

    exec sp_trace_setevent @TraceID, 122, 11, @on

    exec sp_trace_setevent @TraceID, 122, 35, @on

    exec sp_trace_setevent @TraceID, 122, 51, @on

    exec sp_trace_setevent @TraceID, 122, 12, @on

    exec sp_trace_setevent @TraceID, 10, 15, @on

    exec sp_trace_setevent @TraceID, 10, 16, @on

    exec sp_trace_setevent @TraceID, 10, 1, @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, 26, @on

    exec sp_trace_setevent @TraceID, 10, 34, @on

    exec sp_trace_setevent @TraceID, 10, 11, @on

    exec sp_trace_setevent @TraceID, 10, 35, @on

    exec sp_trace_setevent @TraceID, 10, 51, @on

    exec sp_trace_setevent @TraceID, 10, 12, @on

    exec sp_trace_setevent @TraceID, 10, 13, @on

    exec sp_trace_setevent @TraceID, 10, 14, @on

    exec sp_trace_setevent @TraceID, 45, 16, @on

    exec sp_trace_setevent @TraceID, 45, 1, @on

    exec sp_trace_setevent @TraceID, 45, 17, @on

    exec sp_trace_setevent @TraceID, 45, 25, @on

    exec sp_trace_setevent @TraceID, 45, 10, @on

    exec sp_trace_setevent @TraceID, 45, 18, @on

    exec sp_trace_setevent @TraceID, 45, 26, @on

    exec sp_trace_setevent @TraceID, 45, 34, @on

    exec sp_trace_setevent @TraceID, 45, 11, @on

    exec sp_trace_setevent @TraceID, 45, 35, @on

    exec sp_trace_setevent @TraceID, 45, 51, @on

    exec sp_trace_setevent @TraceID, 45, 12, @on

    exec sp_trace_setevent @TraceID, 45, 13, @on

    exec sp_trace_setevent @TraceID, 45, 14, @on

    exec sp_trace_setevent @TraceID, 45, 15, @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, 17, @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, 26, @on

    exec sp_trace_setevent @TraceID, 12, 11, @on

    exec sp_trace_setevent @TraceID, 12, 35, @on

    exec sp_trace_setevent @TraceID, 12, 51, @on

    exec sp_trace_setevent @TraceID, 12, 12, @on

    exec sp_trace_setevent @TraceID, 12, 13, @on

    exec sp_trace_setevent @TraceID, 13, 1, @on

    exec sp_trace_setevent @TraceID, 13, 10, @on

    exec sp_trace_setevent @TraceID, 13, 14, @on

    exec sp_trace_setevent @TraceID, 13, 26, @on

    exec sp_trace_setevent @TraceID, 13, 11, @on

    exec sp_trace_setevent @TraceID, 13, 35, @on

    exec sp_trace_setevent @TraceID, 13, 51, @on

    exec sp_trace_setevent @TraceID, 13, 12, @on

    -- Set the Filters

    declare @intfilter int

    declare @bigintfilter bigint

    exec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Server Profiler - c3053c7d-21f5-49b5-b792-a6a1e3047a62'

    set @bigintfilter = 100000

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

    exec sp_trace_setfilter @TraceID, 35, 0, 6, N'<I put my db name here>'

    -- 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:

    go

    “If your actions inspire others to dream more, learn more, do more and become more, you are a leader.” -- John Quincy Adams

  • Sapen (10/3/2011)


    every time I run the script it runs successfully but only generates a 5mb trace file. But in the actual template before scripting it out I enabled it rollover after 50mb. Also I have even mentioned that the end time for this trace as 10:30 tonight, before scripting it out. But still it runs only for a couple of seconds and says job completed successfully.

    That script will run for a second or two. All it does is start the trace, the trace runs as a background process.

    You can see info on active traces with sys.traces, and start or stop a trace with sp_trace_setstatus.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Just a PS. While the trace is running, even doing all the refreshes in the world you won't see the real file size untill it stops or rolls over.

    What you can do in windows is to copy to file and see the real size in the copy.

  • Thank You.

    One more thing...can we increase the trace file size while the trace is running?

    “If your actions inspire others to dream more, learn more, do more and become more, you are a leader.” -- John Quincy Adams

  • No. That's something you define as part of the trace definition.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Sapen (10/3/2011)


    exec @rc = sp_trace_create @TraceID output, 0, N'E:\Trace\Trace', @maxfilesize, @Datetime

    this is the default when scripting a trace from Profiler, despite setting the rollover in the GUI it disables it in the script. This will create the server side trace with rollover enabled

    exec @rc = sp_trace_create @TraceID output, 2, N'E:\Trace\Trace', @maxfilesize, @Datetime

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

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

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