Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Scheduling SQL Server Traces - Part 2 Expand / Collapse
Author
Message
Posted Sunday, August 31, 2003 12:00 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, October 02, 2013 9:26 AM
Points: 265, Visits: 185
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/rsharma/schedulingsqlservertracespart2.asp
Post #15813
Posted Tuesday, September 16, 2003 4:30 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, February 27, 2013 1:50 AM
Points: 27, Visits: 17
Nice Thing

This is similar procedure for starting trace
that I'm using in daily processing.

CREATE PROCEDURE sp_startTrace
AS
DECLARE @TraceIdOut INT
DECLARE @FolderTrace nvarchar(128)
DECLARE @FileTraceLike nvarchar(128)
DECLARE @FileTrace nvarchar(128)
SELECT @FolderTrace = 'C:\FolderTrace\'
SET @FileTraceLike = @FolderTrace + 'Trace%'
IF
(select count(*) from ::fn_trace_getinfo(default)
where CAST(value AS VARCHAR) like cast(@FileTraceLike AS VARCHAR))
> 0
BEGIN
PRINT 'Already started'
RETURN
END
--------------trace file name TraceYYMMDDHHMMSS
SET @FileTrace = @FolderTrace + 'Trace' +
(select convert(CHAR(6),Getdate(), 12)) +
SUBSTRING((select convert(CHAR(8),Getdate(), 108)),1,2)+
SUBSTRING((select convert(CHAR(8),Getdate(), 108)),4,2)+
SUBSTRING((select convert(CHAR(8),Getdate(), 108)),7,2)
DECLARE @onValue as bit
SET @onValue = 1
DECLARE @maxfilesizeValue bigint
SET @maxfilesizeValue = 1
exec Master..sp_trace_create @TraceIdOut OUT,
@Options =2,
@TraceFile = @FileTrace,
@maxfilesize = @maxfilesizeValue
DECLARE Events_Cursor CURSOR FOR
SELECT 10 As EventID
UNION SELECT 11
UNION SELECT 12
UNION SELECT 13
UNION SELECT 16
UNION SELECT 17
UNION SELECT 21
UNION SELECT 22
UNION SELECT 25
UNION SELECT 33
UNION SELECT 37
UNION SELECT 40
UNION SELECT 41
UNION SELECT 42
UNION SELECT 43
UNION SELECT 53
UNION SELECT 55
UNION SELECT 59
UNION SELECT 61
UNION SELECT 67
UNION SELECT 69
UNION SELECT 74
UNION SELECT 78
UNION SELECT 79
UNION SELECT 80
UNION SELECT 92
UNION SELECT 93
UNION SELECT 100
OPEN Events_Cursor
DECLARE @EventID INT
FETCH NEXT FROM Events_Cursor INTO @EventID
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE Columns_Cursor CURSOR FOR
SELECT 1 AS ColID
UNION SELECT 3
UNION SELECT 6
UNION SELECT 8
UNION SELECT 10
UNION SELECT 11
UNION SELECT 12
UNION SELECT 13
UNION SELECT 14
UNION SELECT 15
UNION SELECT 18
UNION SELECT 27
UNION SELECT 40
OPEN Columns_Cursor
DECLARE @ColumnID INT
FETCH NEXT FROM Columns_Cursor INTO @ColumnID
WHILE @@FETCH_STATUS = 0
BEGIN
exec Master..sp_trace_setevent @TraceId = @TraceIdOut,
@EventID = @EventID ,
@columnid = @ColumnID ,
@on =@onValue
FETCH NEXT FROM Columns_Cursor INTO @ColumnID
END
CLOSE Columns_Cursor
DEALLOCATE Columns_Cursor
FETCH NEXT FROM Events_Cursor INTO @EventID
END
CLOSE Events_Cursor
DEALLOCATE Events_Cursor
----------- Filter
exec Master..sp_trace_setfilter @traceid = @TraceIdOut,
@columnid = 3,
@logical_operator = 0,
@comparison_operator = 0,
@value = 15
exec Master..sp_trace_setfilter @traceid = @TraceIdOut,
@columnid = 10,
@logical_operator = 0,
@comparison_operator = 7,
@value = N'SQL Profiler'
exec Master..sp_trace_setstatus @traceid = @TraceIdOut ,
@Status = 1
print ' Started Trace ' + @FileTrace
GO






Post #77330
Posted Tuesday, September 16, 2003 4:03 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Today @ 1:27 PM
Points: 71, Visits: 54
Interesting concept - But difficult to read and I have found several problems with the code (On SQL2k sp2 it would not run without some fixes.)





Post #77331
Posted Thursday, September 18, 2003 3:21 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, October 02, 2013 9:26 AM
Points: 265, Visits: 185
The comments are in-between the script itself and are self-explanatory hence I did not elaborate on them in text assuming that the user is familiar with sql and the functions used within the code.

Also, the last that I tested it was on SS2K + SP3a....don't have SP2 only on a machine to test on so can't comment on what the issue might be on just SP2 (shouldn't be a big deal though since between SP2 and SP3a most of them have been bug fixes and new features like fn_get_sql etc. are not being used in the code). And when you cut and paste the code, make sure that the text is not messed up because of the font size for the comments in the code (it can wrap up and appear on the second line since the comments are marked as --).

Rahul Sharma
Senior Database Administrator
Manhattan Associates
Atlanta, GA

Edited by - rsharma on 09/19/2003 11:06:29 AM

Edited by - rsharma on 09/19/2003 11:11:16 AM
Post #77332
Posted Friday, October 24, 2003 2:42 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, September 13, 2013 2:41 PM
Points: 49, Visits: 42
Great script! Thanks




Post #77333
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse