<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>remidian.com &#187; SQL Trace</title>
	<atom:link href="http://remidian.com/category/mssql/sql-trace/feed" rel="self" type="application/rss+xml" />
	<link>http://remidian.com</link>
	<description>Braindumps of Remi Visser, freelance Oracle DBA.</description>
	<lastBuildDate>Mon, 10 May 2010 12:33:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Use filters to keep your traces meaningfull</title>
		<link>http://remidian.com/mssql/sql-trace/use-filters-to-keep-your-traces-meaningfull.html</link>
		<comments>http://remidian.com/mssql/sql-trace/use-filters-to-keep-your-traces-meaningfull.html#comments</comments>
		<pubDate>Tue, 14 Nov 2006 17:35:27 +0000</pubDate>
		<dc:creator>remivisser</dc:creator>
				<category><![CDATA[SQL Trace]]></category>

		<guid isPermaLink="false">http://remidian.com/mssql/sql-trace/use-filters-to-keep-your-traces-meaningfull.html</guid>
		<description><![CDATA[Say you have an sql trace for the event &#8216;TSQL SQL:StmtCompleted&#8217; you are, most probably, NOT interested in the sql statements executed through the SQL Server Agent for instance. Filters below remove most of the unwanted &#8216;internal&#8217; tsql. The contents of your tracefile will become more meanigfull and not unimportant small &#8230; Filter out &#8216;internal&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>
Say you have an sql trace for the event &#8216;TSQL SQL:StmtCompleted&#8217; you are, most probably, NOT interested in the sql statements executed through the SQL Server Agent for instance. <span id="more-34"></span> Filters below remove most of the unwanted &#8216;internal&#8217; tsql.
</p>
<p>
The contents of your tracefile will become more meanigfull and not unimportant small &#8230;
</p>
<h3>Filter out &#8216;internal&#8217; sql server proceses</h3>
<h6>Filter on &#8216;ApplicationName&#8217;</h6>
<pre>
&#45;- &#45;-
&#45;- ApplicationName
&nbsp;
&#45;- SQL Profiler sessions
exec sp_trace_setfilter @TraceID, 10, 0, 7, N&#039;SQL Profiler&#039;
&nbsp;
&#45;- SQL executed by the SQL Agent
exec sp_trace_setfilter @TraceID, 10, 0, 7, N&#039;SQLAgent%&#039;
exec sp_trace_setfilter @TraceID, 10, 0, 7, N&#039;SQLDMO_1%&#039;
&nbsp;
</pre>
<h6>Filter on &#8216;LoginName&#8217;</h6>
<pre>
&#45;- &#45;-
&#45;- LoginName
&nbsp;
exec sp_trace_setfilter @TraceID, 11, 0, 7, N&#039;remivisser&#039;
exec sp_trace_setfilter @TraceID, 11, 0, 7, N&#039;&lt;username&gt;&#039;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://remidian.com/mssql/sql-trace/use-filters-to-keep-your-traces-meaningfull.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Trace Reference</title>
		<link>http://remidian.com/mssql/sql-trace/sql-trace-reference.html</link>
		<comments>http://remidian.com/mssql/sql-trace/sql-trace-reference.html#comments</comments>
		<pubDate>Thu, 07 Sep 2006 16:05:17 +0000</pubDate>
		<dc:creator>remivisser</dc:creator>
				<category><![CDATA[SQL Trace]]></category>

		<guid isPermaLink="false">http://remidian.com/mssql/displayalter-running-traces.html</guid>
		<description><![CDATA[Display/Alter running traces or an alternative way to shutdown your server (when &#8216;c2 audit mode&#8217; is enabled). Display running traces When &#8216;c2 audit mode&#8217; is enabled you will see a trace running at all times. Whenever the server can&#8217;t write to it&#8217;s trace file it will shut itself down. (You need to restart with the [...]]]></description>
			<content:encoded><![CDATA[<p>
Display/Alter running traces <em>or</em> an alternative way to shutdown your server (when &#8216;c2 audit mode&#8217; is enabled).<span id="more-22"></span>
</p>
<h3>Display running traces</h3>
<p>
When &#8216;c2 audit mode&#8217; is enabled you will see a trace running at all times. Whenever the server can&#8217;t write to it&#8217;s trace file it will shut itself down. (You need to restart with the -f switch to fix your problem).
</p>
<p>
Example below first displays all running traces and next aborts the trace &#8216;facilitating&#8217; the &#8216;c2 audit mode&#8217; option. The following functions are used, <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fa-fz_04yx.asp"><strong>::fn_trace_getinfo</strong></a> (displays information about runing traces) and <a href="http://msdn2.microsoft.com/en-us/library/ms176034.aspx"><strong>sp_trace_setstatus</strong></a> (used to alter the status of a trace).
</p>
<pre>
1&gt; exec sp_configure &quot;c2 audit mode&quot;
2&gt; go
 name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minimum&nbsp;&nbsp;&nbsp;&nbsp; maximum&nbsp;&nbsp;&nbsp;&nbsp; config_value run_value
 &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;&#45;-- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;-- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;-- &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;--
 c2 audit mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1
&nbsp;
1&gt; select traceid, property, cast(value as char(64)) as value from ::fn_trace_getinfo(0)
2&gt; go
 traceid&nbsp;&nbsp;&nbsp;&nbsp; property&nbsp;&nbsp;&nbsp;&nbsp;value
 &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;-- &#45;&#45;-&#45;&#45;-&#45;&#45;&#45;-- &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 6
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 C:\\Program Files\\Microsoft SQL Server\\MSSQL\\data\\audittrace_200609061836
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 200
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 NULL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5 1
&nbsp;
(5 rows affected)
</pre>
<h3>Alter status of a running trace</h3>
<p>
To alter the status of a trace, eg starting/stopping it you use the <a href="http://msdn2.microsoft.com/en-us/library/ms176034.aspx"><strong>sp_trace_setstatus</strong></a>  function. This function takes two arguments; @traceid &#8211; the id of the trace and @status &#8211; the status of the trace, where status is one of the three options below;
</p>
<ul>
<li>0 &#8211; Stops the specified trace.</li>
<li>1 &#8211; Starts the specified trace.</li>
<li>2 &#8211; Closes the specified trace and deletes its definition from the server.</li>
</ul>
<p>
Now watch the results of aborting the trace in an MS SQLServer instance that is running in â€˜c2 audit modeâ€™;
</p>
<pre>
1&gt; exec sp_trace_setstatus 1, 0
2&gt; go
[DBNETLIB]ConnectionCheckForData (CheckforData()).
[DBNETLIB]General network error. Check your network documentation.
$</pre>
<p>
Do not try this at home, the server shuts itself down.
</p>
<p>
The shutdown seems rather rude as I can not find any information in the mssqlserver logfile as to why it aborted.
</p>
<p>
<a href="http://www.sqlmag.com/Article/ArticleID/44147/sql_server_44147.html">See this article by Brian Moran</a> where I got the inspiration to try this one out &#8230;
</p>
<h3>Handy Scripts</h3>
<p>
Some handy scripts :
</p>
<h6>Script to display running traces</h6>
<pre>
select traceid,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case property
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when 1 then &#039;Trace Options&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when 2 then &#039;FileName&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when 3 then &#039;MaxSize&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when 4 then &#039;StopTime&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when 5 then &#039;Current Trace status&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end property,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cast(value as char(64)) as value
&nbsp;&nbsp;from ::fn_trace_getinfo( 0)
go
&nbsp;
</pre>
<h6>Script below generates commands to stop and close all runing traces</h6>
<pre>
select &#039;exec sp_trace_setstatus &#039; + cast( traceid as varchar(8)) + &#039;, 0&#039; + char(10) +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#039;exec sp_trace_setstatus &#039; + cast( traceid as varchar(8)) + &#039;, 2&#039;
&nbsp;&nbsp;from ::fn_trace_getinfo(0)
 where property = 1
go
&nbsp;
</pre>
<h6>Retrieve trace file data using <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fa-fz_04yx.asp">::fn_trace_gettable</a> function.</h6>
<pre>
select * 
&nbsp;&nbsp;from ::fn_trace_gettable( &#039;E:\\mssql\\admin\\iNYC01\\audit\\AUD_TSQLSTMT_2006-11-14.trc&#039;, default)
go
&nbsp;
select * 
&nbsp;&nbsp;into t_trace 
&nbsp;&nbsp;from ::fn_trace_gettable( &#039;E:\\mssql\\admin\\iNYC01\\audit\\AUD_TSQLSTMT_2006-11-14.trc&#039;, default)
go
&nbsp;
</pre>
<h3>URI&#8217;s from the documentation</h3>
<ul>
<li><a href="http://msdn2.microsoft.com/en-us/library/aa173918(SQL.80).aspx">Monitoring with SQL Profiler</a></li>
<li><a href="http://msdn2.microsoft.com/en-us/library/aa173871(SQL.80).aspx">SQL Profiler Event Classes</a></li>
<li><a href="http://msdn2.microsoft.com/en-us/library/aa173882(SQL.80).aspx">SQL Profiler Data Columns</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://remidian.com/mssql/sql-trace/sql-trace-reference.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
