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 123»»»

Stairway to Server-side Tracing - Step 2: Creating a SQL Trace Using T-SQL (Stairway Series) Expand / Collapse
Author
Message
Posted Monday, February 14, 2011 10:37 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 6:13 PM
Points: 59, Visits: 312
Comments posted to this topic are about the item Stairway to Server-side Tracing - Step 2: Creating a SQL Trace Using T-SQL (Stairway Series)
Post #1063678
Posted Monday, February 21, 2011 4:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, November 27, 2013 8:04 AM
Points: 3, Visits: 17
I copied the script used to list all possible trace events and columns and executed on my sql server 2005 SP3 system. It returns only 14 rows (in other words not all possible categories - )

Is there something I am missing here?

The categories returned are:
Locks
Scans
Security Audit
Stored Procedures
Transactions
TSQL

Thanks for your help.



Post #1067007
Posted Monday, February 21, 2011 10:43 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 6:13 PM
Points: 59, Visits: 312
The query has an unintended predicate in the sys.trace_event_bindings JOIN clause. I thought this was removed from the final article draft but it looks like I erred. Below is the corrected version, which returns 3965 rows under SQL 2005.

I'll get the query in the article corrected. Thanks for pointing this out.

--list all possible trace events and columns
SELECT tcat.name AS EventCategoryName ,
tevent.name AS EventClassName ,
tcolumn.name AS EventColumn ,
tevent.trace_event_id AS EventID ,
tbinding.trace_column_id AS ColumnID ,
tcolumn.type_name AS DataType
FROM sys.trace_categories AS tcat
JOIN sys.trace_events AS tevent ON tevent.category_id = tcat.category_id
JOIN sys.trace_event_bindings AS tbinding ON tbinding.trace_event_id = tevent.trace_event_id
JOIN sys.trace_columns AS tcolumn ON tcolumn.trace_column_id = tbinding.trace_column_id
ORDER BY tcat.name ,
EventClassName ,
EventColumn ;
Post #1067203
Posted Monday, February 21, 2011 9:02 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, November 27, 2013 8:04 AM
Points: 3, Visits: 17
Thanks Dan. The updated query now returns the full resultset.


Post #1067389
Posted Wednesday, February 23, 2011 12:58 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, November 9, 2012 2:48 PM
Points: 493, Visits: 636
Excellent article. I also wanted to let you know about your additional predicate, but you've already identified it. I have written server side traces like this for years, but I always went against sys.trace_events and sys.trace_columns and was unaware of the sys.trace_event_bindings view. I have added the corrected version of your script to give me a better result set of possible events/columns to choose from.

I try to use server side scripting exclusively even with dev/test environments. It seems a bit tedious at first, but since I already have something to start from there isn't that much to add/subtract usually. Further, the process of dealing with profiler is at least as tedious.

Thanks for the article,

Toby
Post #1068495
Posted Wednesday, February 23, 2011 1:10 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, November 9, 2012 2:48 PM
Points: 493, Visits: 636
Oh, there is one issue I wanted to discuss. It's not a problem with your article, but a problem I have struggled with in the past.

I often set the file name like so:

SELECT @File = Substring(Path,1,len(Path)-charindex('\',reverse(path))+1) + @File
FROM sys.traces
WHERE id = 1

Where the value of the @file variable is "Performance", "Duration" or something to that effect. The problem is that if the file already exists the sp_trace_create procedure fails. The two ways I have used to cope with this is check for existence with xp_fileexists and then either bail, or use xp_cmdshell programmatically to remove the file. I have never liked either of my options, and I wish there was a way to automatically overwrite the file if it exists on the sp_trace_create procedure.

I suppose another option would be to check file existence, then append a number in a loop until I get one that doesn't exist.

Do you have any thoughts or suggestions related to this problem?
Post #1068504
Posted Wednesday, February 23, 2011 9:03 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 6:13 PM
Points: 59, Visits: 312
Hi, Toby.

I also wish sp_trace_create had an option to overwrite an existing file. I'm not a big fan of file manipulation in T-SQL either.

You might consider making a habit of the TRACE_FILE_ROLLOVER (option 2) with a file count of 2, even if you only need a single file for a one-time trace. This way, SQL Trace will add the incremental number to the file name if the base file name already exists and automatically delete the n-2 file.

I'll cover trace data and file management later in this Stairway.
Post #1068642
Posted Wednesday, March 23, 2011 9:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 17, 2014 3:05 PM
Points: 8, Visits: 23
Thanks Dan for the article. I'll hope for the next ones.


Leonel E. Umaña Araya
leo_umana@hotmail.com
Post #1082801
Posted Wednesday, March 23, 2011 11:34 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:15 AM
Points: 5,471, Visits: 1,402
I am loving reading these articles... Thank you.

Paul



Post #1083093
Posted Saturday, March 26, 2011 9:13 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Sunday, December 14, 2014 11:17 PM
Points: 89, Visits: 161
Good Article.. Thanks for posting such helpful topics...

Thanks & Regards,
Kartik M Kumar..
Post #1084446
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse