SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Scheduling SQL Server Traces - Part 2


Scheduling SQL Server Traces - Part 2

Author
Message
rsharma
rsharma
SSC-Addicted
SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)

Group: General Forum Members
Points: 403 Visits: 185
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/rsharma/schedulingsqlservertracespart2.asp
s_popovski
s_popovski
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 28
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



dyoder@rainbird.com
dyoder@rainbird.com
SSC Journeyman
SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)

Group: General Forum Members
Points: 91 Visits: 59
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.)



rsharma
rsharma
SSC-Addicted
SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)SSC-Addicted (403 reputation)

Group: General Forum Members
Points: 403 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
currym
currym
SSC Journeyman
SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)

Group: General Forum Members
Points: 87 Visits: 57
Great script! Thanks



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search