|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, May 11, 2012 3:58 AM
Points: 265,
Visits: 184
|
|
|
|
|
|
SSC 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
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, September 17, 2012 10:19 AM
Points: 71,
Visits: 49
|
|
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.)
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, May 11, 2012 3:58 AM
Points: 265,
Visits: 184
|
|
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
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, August 30, 2012 12:27 PM
Points: 49,
Visits: 38
|
|
|
|
|