<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Web Developer - Author(s): Jes Schultz Borland (grrlgeek)</title>
		<link>http://blogs.lessthandot.com/index.php/WebDev/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2" />
		<description></description>
		<language>en-GB</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>SQL Server: Starting a Server-Side Trace</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/WebDesignGraphicsStyling/starting-a-sql-server-side-trace</link>
			<pubDate>Fri, 10 Dec 2010 14:17:42 +0000</pubDate>			<dc:creator>Jes Schultz Borland (grrlgeek)</dc:creator>
			<category domain="main">Web Design, Graphics &amp; Styling</category>			<guid isPermaLink="false">1040@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Stop me if you&#039;ve heard this one...a programmer walks up to a DBA and says, &quot;The database is slow.&quot; &lt;/p&gt;

&lt;p&gt;One of the many performance tuning and troubleshooting tools in the SQL Server DBA toolbelt is Profiler. You pick events you want to see, set up a trace, and watch the events roll by. The problem is that this graphical tool, especially when run from a workstation, can place a heavy load on the server. &lt;/p&gt;

&lt;p&gt;A better way to perform a trace of events is to run it on the server. I was asked to do this at work last week, and had to say, &quot;I don&#039;t know how to do that.&quot; I learned something new, and I want to share it with you! &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Setting Up the Trace &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;First, set up the trace using SQL Server Profiler, preferably against a development or test database. (The GUI tool can negatively affect performance, so be careful on production databases.) To do this, in SSMS go to Tools &gt; SQL Server Profiler. Add a trace name, choose to save to a file, and enable file rollover. This last option means that when the max file size is reached, a new file will be created. &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerPropertiesGeneral.JPG&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;886&quot; height=&quot;641&quot; /&gt;&lt;/div&gt;
&lt;p&gt; &lt;br /&gt;
Next, go to Events Selection and check your events. I&amp;#8217;ve chosen a standard template for this test. &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerPropertiesEvents.JPG&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;888&quot; height=&quot;641&quot; /&gt;&lt;/div&gt;
&lt;p&gt;  &lt;br /&gt;
Click &amp;#8220;Run&amp;#8221; to begin the trace. I executed a stored procedure in my AdventureWorks database to make sure the trace was capturing data. &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerRunning.JPG&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;692&quot; height=&quot;565&quot; /&gt;&lt;/div&gt;
&lt;p&gt; &lt;br /&gt;
&lt;b&gt;Making a Server-Side Trace&lt;/b&gt; &lt;/p&gt;

&lt;p&gt;Now, I stop the trace and create the script for a server-side trace. In Profiler, go to File &gt; Export &gt; Script Trace Definition &gt; For SQL Server 2005 &amp;#8211; 2008 R2. You will be prompted to save the .sql file, and notified when it is saved. &lt;/p&gt;

&lt;p&gt;Now, open the .sql file in SQL Server Management Studio. It will look similar to this: &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerTraceSQL.JPG&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;786&quot; height=&quot;520&quot; /&gt;&lt;/div&gt;
&lt;p&gt; &lt;br /&gt;
On line 19, you will need to specify where to save the output files. This might be a location on the server, or a share drive on your network. &lt;/p&gt;

&lt;p&gt;Once those settings have been chosen, verify that you are connected to the correct server and Execute. Ta-da! You&amp;#8217;ve just started a server-side trace. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Stopping the Server-Side Trace &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Eventually, you will probably want to stop this trace. Collecting an infinite amount of data may sound fun, but there won&#039;t be any value in it. &lt;/p&gt;

&lt;p&gt;First, you&amp;#8217;ll need the trace ID. &lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb95550&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; :: &lt;span style=&quot;color: #00AF00;&quot;&gt;fn_trace_getinfo&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb69452&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Your results might look something like this: &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/users/grrlgeek/fn_trace_getinforesults.JPG&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;428&quot; height=&quot;236&quot; /&gt;&lt;/div&gt;
&lt;p&gt; &lt;br /&gt;
Traceid is the ID on the server. I currently have two, 1 and 2. Property is the ID of the trace property. &lt;br /&gt;
&amp;#8226;	1 &amp;#8211; Trace Options&lt;br /&gt;
&amp;#8226;	2 &amp;#8211; File Name &lt;br /&gt;
&amp;#8226;	3 &amp;#8211; Max size &lt;br /&gt;
&amp;#8226;	4 &amp;#8211; Stop time (if set) &lt;br /&gt;
&amp;#8226;	5 &amp;#8211; Current trace status. &lt;/p&gt;

&lt;p&gt;The status options are: &lt;br /&gt;
&amp;#8226;	0 &amp;#8211; Stopped&lt;br /&gt;
&amp;#8226;	1 &amp;#8211; Running &lt;/p&gt;

&lt;p&gt;I determine that the trace I just started has the ID of 2. To stop the trace, I use sp_trace_setstatus. The syntax is &lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb72170&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #AF0000;&quot;&gt;sp_trace_setstatus&lt;/span&gt; traceid, statusid&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb61306&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The status options are: &lt;br /&gt;
&amp;#8226;	0 &amp;#8211; Stop&lt;br /&gt;
&amp;#8226;	1 &amp;#8211; Start &lt;br /&gt;
&amp;#8226;	2 &amp;#8211; Close and delete definition from server &lt;/p&gt;

&lt;p&gt;So, to stop traceid 2, I run this command: &lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb46260&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #AF0000;&quot;&gt;sp_trace_setstatus&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb95881&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;I can verify it has been stopped by re-running &lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb35956&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; :: &lt;span style=&quot;color: #00AF00;&quot;&gt;fn_trace_getinfo&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb13840&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I can then open the .trc file in SQL Server Profiler and examine it for performance issues. &lt;/p&gt;

&lt;p&gt;I was pretty excited to learn this. I hope this can help you out too!&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/WebDesignGraphicsStyling/starting-a-sql-server-side-trace&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Stop me if you've heard this one...a programmer walks up to a DBA and says, "The database is slow." </p>

<p>One of the many performance tuning and troubleshooting tools in the SQL Server DBA toolbelt is Profiler. You pick events you want to see, set up a trace, and watch the events roll by. The problem is that this graphical tool, especially when run from a workstation, can place a heavy load on the server. </p>

<p>A better way to perform a trace of events is to run it on the server. I was asked to do this at work last week, and had to say, "I don't know how to do that." I learned something new, and I want to share it with you! </p>

<p><b>Setting Up the Trace </b></p>

<p>First, set up the trace using SQL Server Profiler, preferably against a development or test database. (The GUI tool can negatively affect performance, so be careful on production databases.) To do this, in SSMS go to Tools > SQL Server Profiler. Add a trace name, choose to save to a file, and enable file rollover. This last option means that when the max file size is reached, a new file will be created. </p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerPropertiesGeneral.JPG" alt="" title="" width="886" height="641" /></div>
<p> <br />
Next, go to Events Selection and check your events. I&#8217;ve chosen a standard template for this test. </p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerPropertiesEvents.JPG" alt="" title="" width="888" height="641" /></div>
<p>  <br />
Click &#8220;Run&#8221; to begin the trace. I executed a stored procedure in my AdventureWorks database to make sure the trace was capturing data. </p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerRunning.JPG" alt="" title="" width="692" height="565" /></div>
<p> <br />
<b>Making a Server-Side Trace</b> </p>

<p>Now, I stop the trace and create the script for a server-side trace. In Profiler, go to File > Export > Script Trace Definition > For SQL Server 2005 &#8211; 2008 R2. You will be prompted to save the .sql file, and notified when it is saved. </p>

<p>Now, open the .sql file in SQL Server Management Studio. It will look similar to this: </p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/users/grrlgeek/ProfilerTraceSQL.JPG" alt="" title="" width="786" height="520" /></div>
<p> <br />
On line 19, you will need to specify where to save the output files. This might be a location on the server, or a share drive on your network. </p>

<p>Once those settings have been chosen, verify that you are connected to the correct server and Execute. Ta-da! You&#8217;ve just started a server-side trace. </p>

<p><b>Stopping the Server-Side Trace </b></p>

<p>Eventually, you will probably want to stop this trace. Collecting an infinite amount of data may sound fun, but there won't be any value in it. </p>

<p>First, you&#8217;ll need the trace ID. </p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb30631'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb30631','cb31459'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb30631" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> :: <span style="color: #00AF00;">fn_trace_getinfo</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">default</span><span style="color: #808080;">&#41;</span></li></ol></div><div id="cb31459" style="display: none; color: red;"></div></div></div>

<p>Your results might look something like this: </p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/users/grrlgeek/fn_trace_getinforesults.JPG" alt="" title="" width="428" height="236" /></div>
<p> <br />
Traceid is the ID on the server. I currently have two, 1 and 2. Property is the ID of the trace property. <br />
&#8226;	1 &#8211; Trace Options<br />
&#8226;	2 &#8211; File Name <br />
&#8226;	3 &#8211; Max size <br />
&#8226;	4 &#8211; Stop time (if set) <br />
&#8226;	5 &#8211; Current trace status. </p>

<p>The status options are: <br />
&#8226;	0 &#8211; Stopped<br />
&#8226;	1 &#8211; Running </p>

<p>I determine that the trace I just started has the ID of 2. To stop the trace, I use sp_trace_setstatus. The syntax is </p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb99106'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb99106','cb92921'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb99106" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #AF0000;">sp_trace_setstatus</span> traceid, statusid</li></ol></div><div id="cb92921" style="display: none; color: red;"></div></div></div>

<p>The status options are: <br />
&#8226;	0 &#8211; Stop<br />
&#8226;	1 &#8211; Start <br />
&#8226;	2 &#8211; Close and delete definition from server </p>

<p>So, to stop traceid 2, I run this command: </p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb2338'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb2338','cb58259'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb2338" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #AF0000;">sp_trace_setstatus</span> <span style="color: #000;">2</span>, <span style="color: #000;">0</span></li></ol></div><div id="cb58259" style="display: none; color: red;"></div></div></div><p> </p>

<p>I can verify it has been stopped by re-running </p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb19967'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb19967','cb11430'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb19967" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> * <span style="color: #0000FF;">FROM</span> :: <span style="color: #00AF00;">fn_trace_getinfo</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">default</span><span style="color: #808080;">&#41;</span></li></ol></div><div id="cb11430" style="display: none; color: red;"></div></div></div>

<p>I can then open the .trc file in SQL Server Profiler and examine it for performance issues. </p>

<p>I was pretty excited to learn this. I hope this can help you out too!</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/WebDesignGraphicsStyling/starting-a-sql-server-side-trace">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/WebDesignGraphicsStyling/starting-a-sql-server-side-trace#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=1040</wfw:commentRss>
		</item>
			</channel>
</rss>
