<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Eric Humphrey</title>
	
	<link>http://www.erichumphrey.com</link>
	<description>aka @lotsahelp</description>
	<lastBuildDate>Thu, 29 Mar 2012 20:56:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/EricHumphrey" /><feedburner:info uri="erichumphrey" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>An Amusing New Chapter of My Career</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/1W7hVbv59vs/</link>
		<comments>http://www.erichumphrey.com/2012/03/an-amusing-new-chapter-of-my-career/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 20:56:08 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[job]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=301</guid>
		<description><![CDATA[Starting next week, that&#8217;s the first week of April, this will be my new office. Well, not really, but I&#8217;ll be working for the company that hosts this coaster, Six Flags. I&#8217;ll be overseeing all the SQL Server stuff for the entire organization. That means the back office stuff, plus what it takes to run [...]]]></description>
				<content:encoded><![CDATA[<div id="attachment_303" class="wp-caption alignright" style="width: 310px"><a href="http://www.flickr.com/photos/wallaceperspective/77798734/"><img class="size-medium wp-image-303 " title="77798734_9b0c83f474_n" src="http://www.erichumphrey.com/wp-content/uploads/2012/03/77798734_9b0c83f474_n-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">My New Office</p></div>
<p>Starting next week, that&#8217;s the first week of April, this will be my new office. Well, not really, but I&#8217;ll be working for the company that hosts this coaster, Six Flags. I&#8217;ll be overseeing all the SQL Server stuff for the entire organization. That means the back office stuff, plus what it takes to run all 19 parks. This will offer an interesting set of challenges that I haven&#8217;t had to face before. One example is up-time. During the day, availability must be 100% as many times we won&#8217;t get a second chance to work with a customer. They&#8217;ve gone home, which could be in a different state. Even though we must be up 100% of the time the park is open, the parks don&#8217;t usually stay open 24 hours which helps with maintenance windows.</p>
<p>This will be an exciting change of pace for me and working with an organization whose purpose is to entertain and amuse. I look forward to what this change will bring. Also, if I ever have a stressful day, I can go to the park that is nearby and ride a coaster to chill out. I&#8217;m sure I&#8217;ll be taking advantage of this a lot.</p>
<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/1W7hVbv59vs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2012/03/an-amusing-new-chapter-of-my-career/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2012/03/an-amusing-new-chapter-of-my-career/</feedburner:origLink></item>
		<item>
		<title>T-SQL Tuesday #028 – Jack of All Trades ie Integration Specialist</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/y-c03rl6zfE/</link>
		<comments>http://www.erichumphrey.com/2012/03/t-sql-tuesday-028/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 12:49:02 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[dba]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=291</guid>
		<description><![CDATA[Argenis Fernandez (blog &#124; twitter) is hosting the latest T-SQL Tuesday and asking about specialization. For the earlier part of my career I was doing application development while really wanting to do database work. I also learned plenty about systems administration while in college. The variety of the tasks made me a Jack of All [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://sqlblog.com/blogs/argenis_fernandez/archive/2012/03/05/t-sql-tuesday-028-jack-of-all-trades-master-of-none.aspx"><img class="alignleft size-full wp-image-293" title="TSQL2sDay150x150" src="http://www.erichumphrey.com/wp-content/uploads/2012/03/TSQL2sDay150x150_3D59E3C6.jpg" alt="" width="150" height="150" /></a></p>
<p>Argenis Fernandez (<a href="http://sqlblog.com/blogs/argenis_fernandez">blog</a> | <a href="http://twitter.com/#!/DBArgenis">twitter</a>) is <a href="http://sqlblog.com/blogs/argenis_fernandez/archive/2012/03/05/t-sql-tuesday-028-jack-of-all-trades-master-of-none.aspx">hosting the latest T-SQL Tuesday</a> and asking about specialization.</p>
<p>For the earlier part of my career I was doing application development while really wanting to do database work. I also learned plenty about systems administration while in college. The variety of the tasks made me a Jack of All Trades with a lean toward databases. I wanted to specialize as a DBA or DB developer, just the jobs were never there until I moved to a bigger market.</p>
<p>When I was able to specialize, I was happy I could focus on one thing and get really deep with it. Now I am able to get deep with SQL Server, but I find myself constantly recalling information I learned in my previous positions to help with current issues. CLR, PowerShell, and little custom written utilities all draw from my .NET experience, which I am grateful for. I run into other DBAs that have no clue what goes on outside of their world. Having multiple skills allows me to create better solutions as I don&#8217;t just consider what I&#8217;m responsible for, but all the connections to my piece as well.</p>
<p>Being a generalist early in my career has allowed me better understanding of the whole stack of any given solution. It is easier for me to spot an integration problem or see a problem with an application&#8217;s implementation than it would have been without that variety of experience. Jack of All Trades tend to be better at seeing the big picture as they don&#8217;t focus on just one area. They can be the ones that help everything fit together better. Specialists are an important part of our ecosystem, but without someone to put the pieces together, you would have perfect components in a flawed system. Solutions really are greater than the sum of their parts.</p>
<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/y-c03rl6zfE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2012/03/t-sql-tuesday-028/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2012/03/t-sql-tuesday-028/</feedburner:origLink></item>
		<item>
		<title>Extract CLR Assemblies from SQL Server</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/kSNK8wWniuI/</link>
		<comments>http://www.erichumphrey.com/2012/03/extract-clr-assemblies-from-sql-server/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 21:53:03 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[clr]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=282</guid>
		<description><![CDATA[I&#8217;ve run into a few situations that required examining the existing CLR assemblies on a server. Whether I needed to do a comparison between two versions to make sure they are the same or confirm something in the assembly itself, this script has come in handy. Point it at a database, give it an output [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve run into a few situations that required examining the existing CLR assemblies on a server. Whether I needed to do a comparison between two versions to make sure they are the same or confirm something in the assembly itself, this script has come in handy. Point it at a database, give it an output path and it will save all the assemblies in that database to dlls in the given folder. You can then use a .NET disassembler to confirm suspicions or a binary comparison to make sure the dll matches what it should.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">&lt;#
    .SYNOPSIS
        Extracts CLR Assemblies from a SQL 2005+ database.
&nbsp;
    .DESCRIPTION
        Extracts CLR Assemblies from a SQL 2005+ database.
&nbsp;
    .PARAMETER  ServerInstance
        The Server\Instance to connect to
    .PARAMETER  Database
        The Database to extract assemblies from
    .PARAMETER  OutPath
        The path to output the assemblies
&nbsp;
    .EXAMPLE
        PS C:\&gt; .\Get-SqlAssemblies.ps1 -ServerInstance 'MyServer\MyInstance' -Database 'MyDatabase'
        This example shows how to call Get-SqlAssemblies with named parameters.
&nbsp;
    .INPUTS
        System.String
&nbsp;
    .NOTES
        For more information about advanced functions, call Get-Help with any
        of the topics in the links listed below.
&nbsp;
#&gt;</span>
<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span>
    <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$ServerInstance</span> <span style="color: pink;">=</span> <span style="color: #800000;">'LOCALHOST'</span><span style="color: pink;">,</span>
&nbsp;
    <span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Database</span><span style="color: pink;">,</span>
&nbsp;
    <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$OutPath</span> <span style="color: pink;">=</span> <span style="color: #800000;">'.'</span>
<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;">#Correct for variations of incoming ServerInstance names</span>
<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">-not</span> <span style="color: #800080;">$ServerInstance</span>.Contains<span style="color: #000000;">&#40;</span><span style="color: #800000;">'\'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$ServerInstance</span> <span style="color: pink;">+=</span> <span style="color: #800000;">'\DEFAULT'</span><span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ServerInstance</span>.Contains<span style="color: #000000;">&#40;</span><span style="color: #800000;">','</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #FF0000;">-not</span> <span style="color: #800080;">$ServerInstance</span>.Contains<span style="color: #000000;">&#40;</span><span style="color: #800000;">'<span style="color: #008080; font-weight: bold;">`,</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$ServerInstance</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ServerInstance</span>.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">','</span><span style="color: pink;">,</span> <span style="color: #800000;">'<span style="color: #008080; font-weight: bold;">`,</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">dir</span> SQLSERVER:\SQL\<span style="color: #800080;">$ServerInstance</span>\Databases\<span style="color: #800080;">$Database</span>\Assemblies <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span>
    <span style="color: #000080;">$_</span>.SqlAssemblyFiles <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span>
        <span style="color: #800080;">$str</span> <span style="color: pink;">=</span> <span style="color: #000080;">$_</span>.name
        <span style="color: #800080;">$path</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$OutPath</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$str</span>.Substring<span style="color: #000000;">&#40;</span><span style="color: #800080;">$str</span>.LastIndexOf<span style="color: #000000;">&#40;</span><span style="color: #800000;">'\'</span><span style="color: #000000;">&#41;</span><span style="color: pink;">+</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #008080; font-weight: bold;">Set-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$path</span> <span style="color: #008080; font-style: italic;">-Value</span> <span style="color: #000080;">$_</span>.GetFileBytes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-Encoding</span> byte;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/kSNK8wWniuI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2012/03/extract-clr-assemblies-from-sql-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2012/03/extract-clr-assemblies-from-sql-server/</feedburner:origLink></item>
		<item>
		<title>Split Typeperf Output in More Managable Chunks</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/C4tLafaoMVA/</link>
		<comments>http://www.erichumphrey.com/2012/02/split-typeperfoutput/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 14:15:22 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[dba]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=262</guid>
		<description><![CDATA[I really like using typeperf for perfmon counter collection. It allows me to save a collection of counters to monitor and store those readings in a csv file for later analysis. Sometimes I end up running the output through the PAL tool. Unfortunately, the PAL tool generates graphs that are fairly narrow. Monitoring sessions of [...]]]></description>
				<content:encoded><![CDATA[<p>I really like using <a href="http://technet.microsoft.com/en-us/library/bb490960.aspx">typeperf</a> for perfmon counter collection. It allows me to save a collection of counters to monitor and store those readings in a csv file for later analysis. Sometimes I end up running the output through the <a href="http://pal.codeplex.com/">PAL tool</a>. Unfortunately, the PAL tool generates graphs that are fairly narrow. Monitoring sessions of long duration causes these graphs to be really cramped. I wanted a way to split the typeperf output to get a reasonable amount of data points in these graphs. A side benefit is the processing per file is a lot quicker.</p>
<p>The script takes a filepath as its only argument. It splits by the hour and copies the header row to each new file.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">param</span> <span style="color: #000000;">&#40;</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$filepath</span> <span style="color: #008000;">#incoming file</span>
<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;">#Does the file exist</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Test-Path</span> <span style="color: #800080;">$filepath</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$infile</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Item</span> <span style="color: #800080;">$filepath</span>
	<span style="color: #800080;">$data</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800080;">$infile</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;">#if not, exit the script</span>
<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #800000;">&quot;Failed to find $filepath&quot;</span>
	exit
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">#Get the header to be able to repeat it in each file</span>
<span style="color: #800080;">$header</span> <span style="color: pink;">=</span> <span style="color: #800080;">$data</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-First</span> <span style="color: #804000;">1</span>
<span style="color: #800080;">$lastHour</span> <span style="color: pink;">=</span> <span style="color: #800080;">$null</span>
<span style="color: #800080;">$outFile</span> <span style="color: pink;">=</span> <span style="color: #800080;">$null</span>
&nbsp;
<span style="color: #008000;">#Loop through the data, skipping the header line.</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: pink;">-</span>Skip <span style="color: #804000;">1</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>DateTime<span style="color: #000000;">&#93;</span>::Parse<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #000080;">$_</span>.Substring<span style="color: #000000;">&#40;</span><span style="color: #804000;">1</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #000080;">$_</span>.IndexOf<span style="color: #000000;">&#40;</span><span style="color: #800000;">'&quot;'</span><span style="color: pink;">,</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: pink;">-</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$lastHour</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span> <span style="color: #FF0000;">-or</span> <span style="color: #800080;">$date</span>.Hour <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$lastHour</span>.Hour <span style="color: #FF0000;">-or</span> <span style="color: #800080;">$outFile</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$lastHour</span> <span style="color: pink;">=</span> <span style="color: #800080;">$date</span>.AddMinutes<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #800080;">$date</span>.Minute<span style="color: #000000;">&#41;</span>.AddSeconds<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #800080;">$date</span>.Second<span style="color: #000000;">&#41;</span>
		<span style="color: #800080;">$outFile</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$infile</span>.Directory <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;{0}_{1}{2}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$infile</span>.BaseName<span style="color: pink;">,</span> <span style="color: #800080;">$lastHour</span>.ToString<span style="color: #000000;">&#40;</span><span style="color: #800000;">'yyyyMMdd_HHmmss'</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> <span style="color: #800080;">$infile</span>.extension<span style="color: #000000;">&#41;</span>
		<span style="color: #800080;">$header</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$outFile</span> <span style="color: #008080; font-style: italic;">-Encoding</span> UTF8
	<span style="color: #000000;">&#125;</span>
	<span style="color: #000080;">$_</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$outFile</span> <span style="color: #008080; font-style: italic;">-Encoding</span> UTF8 <span style="color: #008080; font-style: italic;">-Append</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Update:</strong> I cleaned up the script a little based on Jeff&#8217;s comments below.</p>
<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/C4tLafaoMVA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2012/02/split-typeperfoutput/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2012/02/split-typeperfoutput/</feedburner:origLink></item>
		<item>
		<title>Automate CPU-Z Capture to Check for Throttled Processors</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/Z0F_sVYwn_Y/</link>
		<comments>http://www.erichumphrey.com/2012/02/automate-cpuz/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 14:00:34 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[dba]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=257</guid>
		<description><![CDATA[Several professionals have posted about checking whether or not your processors are running at full speed by using CPU-Z. Some recommendations are to check your servers every couple of months or, if virtual, every time your guest moves. Me being lazy efficient, I&#8217;d rather automate having these servers send me their info on a scheduled [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.sqlskills.com/blogs/paul/post/are-your-cpus-running-slowly-tool-tip-and-survey.aspx">Several</a> <a href="http://www.brentozar.com/archive/2010/10/sql-server-on-powersaving-cpus-not-so-fast/">professionals</a> <a href="http://colleenmorrow.com/2011/12/29/sql-server-a-to-z-cpu-z/">have</a> <a href="http://sqlserverperformance.wordpress.com/tag/cpu-z/">posted</a> about checking whether or not your processors are running at full speed by using <a href="http://www.cpuid.com/softwares/cpu-z.html">CPU-Z</a>. Some recommendations are to check your servers every couple of months or, if virtual, every time your guest moves. Me being <del>lazy</del> efficient, I&#8217;d rather automate having these servers send me their info on a scheduled basis.</p>
<p>First things, first. Be sure to copy CPU-Z out to all your servers, preferably in a consistent folder. Edit the cpuz.ini file to turn off extra scanning (we just need the CPU info).</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">ACPI</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
<span style="color: #000099;">PCI</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
<span style="color: #000099;">DMI</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
<span style="color: #000099;">Sensor</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
<span style="color: #000099;">SMBus</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
<span style="color: #000099;">Display</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span></pre></td></tr></table></div>

<p>Save the following as a script and schedule it to run on a monthly or so basis using your favorite scheduler. The email portion was taken from <a href="http://www.techrepublic.com/blog/window-on-windows/send-an-email-with-an-attachment-using-powershell/4969">this post</a>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: pink;">&amp;</span> <span style="color: #800000;">'.\cpuz64.exe'</span> <span style="color: #800000;">&quot;-txt=$env:COMPUTERNAME&quot;</span>
<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #804000;">15</span> <span style="color: #008000;">#Give CPUZ enough time to generate output</span>
&nbsp;
<span style="color: #800080;">$smtpServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;127.0.0.1&quot;</span>
<span style="color: #800080;">$msg</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.MailMessage
<span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$smtpServer</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$msg</span>.From <span style="color: pink;">=</span> <span style="color: #800000;">&quot;emailadmin@test.com&quot;</span>
<span style="color: #800080;">$msg</span>.To.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;administrator1@test.com&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$msg</span>.To.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;administrator2@test.com&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$msg</span>.Subject <span style="color: pink;">=</span> <span style="color: #800000;">&quot;[CPU-Z] $env:COMPUTERNAME&quot;</span>
<span style="color: #800080;">$msg</span>.Body <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">gc</span> <span style="color: #800000;">&quot;$env:COMPUTERNAME.txt&quot;</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;(Specification|Core Speed|Stock frequency)&quot;</span><span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$msg</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/Z0F_sVYwn_Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2012/02/automate-cpuz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2012/02/automate-cpuz/</feedburner:origLink></item>
		<item>
		<title>Script level upgrade for database ‘master’ failed</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/zvgmQ102jYY/</link>
		<comments>http://www.erichumphrey.com/2011/11/script-level-upgrade-for-database-master-failed/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 16:17:04 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[clusters]]></category>
		<category><![CDATA[dba]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=248</guid>
		<description><![CDATA[A few weeks ago one of our clustered server nodes blue-screened and when it came back on SQL refused to start. I started digging in and this is what I found in the Event Log: &#8220;Script level upgrade for database &#8216;master&#8217; failed because upgrade step &#8216;sqlagent100_msdb_upgrade.sql&#8217; encountered error 200, state 7, severity 25.&#8221; Immediately I [...]]]></description>
				<content:encoded><![CDATA[<p>A few weeks ago one of our clustered server nodes blue-screened and when it came back on SQL refused to start. I started digging in and this is what I found in the Event Log: &#8220;Script level upgrade for database &#8216;master&#8217; failed because upgrade step &#8216;sqlagent100_msdb_upgrade.sql&#8217; encountered error 200, state 7, severity 25.&#8221; Immediately I started to suspect a corrupt master database. And I found this in the SQL Error Log:</p>
<blockquote><p>Creating procedure sp_sqlagent_get_perf_counters&#8230;<br />
Error: 468, Severity: 16, State: 9.<br />
<strong>Cannot resolve the collation conflict between &#8220;SQL_Latin1_General_CP1_CI_AS&#8221; and &#8220;Latin1_General_CI_AS&#8221; in the equal to operation.</strong><br />
Error: 912, Severity: 21, State: 2.<br />
Script level upgrade for database &#8216;master&#8217; failed because upgrade step &#8216;sqlagent100_msdb_upgrade.sql&#8217; encountered error 200, state 7, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the &#8216;master&#8217; database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.<br />
Error: 3417, Severity: 21, State: 3.<br />
Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.<br />
SQL Trace was stopped due to server shutdown. Trace ID = &#8217;1&#8242;. This is an informational message only; preser action is required.</p></blockquote>
<p>It turns out that the collation of msdb did not match master. Master was using SQL_Latin1_General_CP1_CI_AS while only msdb and one other database was using  Latin1_General_CI_AS. The upgrade script that SQL Server ran at startup performed a join across those two databases resulting in the error. I&#8217;m still not sure about why this script got run as no service packs / cumulative updates had been applied to this server recently and it was originally installed as 2008, not an upgrade from 2005. With the upgrade script interrupted, it left the master db unusable.</p>
<p>I started going through the <a href="http://msdn.microsoft.com/en-us/library/ms190679.aspx">steps to restore master</a>. I was able to <a href="http://msdn.microsoft.com/en-us/library/ms188236%28v=sql.100%29.aspx">start the server in single user mode</a>, yet I could never get in as the single user. Something seemed to always be taking the connection before I could get in.</p>
<p>I had a long, long conversation with the #sqlhelp folks on Twitter about this. All of these guys and gals were tossing out help: @sqlinsaneo @kbriankelly @darrelllandrum @rusanu @DBArgenis @Kendra_Little @mrdenny @Bugboi @SQLSoldier. We stopped all services that were known to connect, stopped the browser service, changed the port, only allow IP connections, paused the cluster node I was working on, and still I was getting an error that only one admin was allowed at a time in single user mode.</p>
<p>Since I was getting nowhere fast, I decided on a different tact, namely to <a href="https://blogs.msdn.com/themes/blogs/generic/post.aspx?WeblogApp=psssql&amp;y=2008&amp;m=08&amp;d=29&amp;WeblogPostName=how-to-rebuild-system-databases-in-sql-server-2008&amp;GroupKeys=">rebuild master</a> then recover from backup. Rebuilding master was a fairly quick process. An important note about rebuilding master is that is also rebuilds msdb. Now I had two databases to recover from backup. Once the rebuild was complete, I was successfully able to start the service in single user mode  and was able to connect (yay!!!). Now I could restore a backup of master, restart SQL normally and restore msdb. I finally had a running instance 2.5 hours later.</p>
<p>Important lessons learned from this experience:</p>
<ul>
<li>If single user mode isn&#8217;t working and you have a good backup of msdb, rebuild then recover. Rebuilding might fix some issues and get you on the road to recovery quicker.</li>
<li>Collations of all the system databases really should match. This whole issue was because of a collation conflict between master and msdb.</li>
</ul>
<div>Thanks again to:</div>
<div>
<ul>
<li>Allen Kinsel (<a href="http://www.allenkinsel.com">blog</a> | <a href="http://twitter.com/#!/sqlinsaneo">twitter</a>)</li>
<li>K. Brian Kelley (<a href="http://www.truthsolutions.com">blog</a> | <a href="http://twitter.com/#!/kbriankelley">twitter</a>)</li>
<li>Darrell Landrum (<a href="http://twitter.com/#!/darrelllandrum">twitter</a>)</li>
<li>Remus Rusanu (<a href="http://rusanu.com">blog</a> | <a href="http://twitter.com/#!/rusanu">twitter</a>)</li>
<li>Argenis Fernandez (<a href="http://www.sqlblog.com/blogs/argenis_fernandez">blog</a> | <a href="http://twitter.com/#!/DBArgenis">twitter</a>)</li>
<li>Kendra Little (<a href="http://littlekendra.com">blog</a> | <a href="http://twitter.com/#!/Kendra_Little">twitter</a>)</li>
<li>Denny Cherry (<a href="http://www.mrdenny.com">blog</a> | <a href="http://twitter.com/#!/mrdenny">twitter</a>)</li>
<li>Bugboi (<a href="http://twitter.com/#!/Bugboi">twitter</a>)</li>
<li>Robert Davis (<a href="http://www.sqlsoldier.com">blog</a> | <a href="http://twitter.com/#!/SQLSoldier">twitter</a>)</li>
</ul>
</div>
<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/zvgmQ102jYY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2011/11/script-level-upgrade-for-database-master-failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2011/11/script-level-upgrade-for-database-master-failed/</feedburner:origLink></item>
		<item>
		<title>Sync SSMS Tools Pack Across Computers Using SyncToy</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/hiXVCsAOHmg/</link>
		<comments>http://www.erichumphrey.com/2011/10/synctoy-ssmstools/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 18:44:06 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[dba]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=243</guid>
		<description><![CDATA[My favorite and most used feature of the SSMS Tools Pack is the query history. This feature has saved me a lot of time and effort. DBAs where I work are assigned both a desktop for normal day to day operations and a laptop for when we&#8217;re at home, meetings, travel, etc. Today I ran [...]]]></description>
				<content:encoded><![CDATA[<p>My favorite and most used feature of the <a href="http://www.ssmstoolspack.com/">SSMS Tools Pack</a> is the query history. This feature has saved me a lot of time and effort. DBAs where I work are assigned both a desktop for normal day to day operations and a laptop for when we&#8217;re at home, meetings, travel, etc. Today I ran into a scenario that made me want to keep the query history of both machines in sync. I asked <a href="http://twitter.com/#!/MladenPrajdic">Mladen Prajdic</a>, the creator, about syncing across computers and he directed me to a <a href="http://www.real-sql-guy.com/2011/10/wonder-twin-powers-activate.html">blog post</a> written by <a href="https://twitter.com/#!/RealSQLGuy">REAL SQL Guy</a> that does just that. Unfortunately his method uses Dropbox which is blocked at work, so I needed an alternative. I use <a href="https://www.microsoft.com/download/en/details.aspx?id=15155">SyncToy</a> from Microsoft regularly to keep other folders in sync, so I decided to do the same for this project. Using SyncToy manually means that both machines need to be powered on and can see each other on the network since there is no intermediary.</p>
<p>The first thing I did was to share the C:\SSMSTools folder on each machine so I can trigger the sync from whichever computer I&#8217;m sitting at. I then created a folder pair on each machine specifying the &#8220;Left&#8221; folder as the remote shared folder and the &#8220;Right&#8221; folder as the local one. I made sure to use the &#8220;Synchronize&#8221; setting so that changes can go both ways. Give it a name, click Preview and Run. Now I have my entire history from both machines available from either one.</p>
<p>Link Recap:</p>
<ul>
<li><a href="http://www.ssmstoolspack.com/">SSMS Tools Pack</a></li>
<li><a href="http://www.real-sql-guy.com/2011/10/wonder-twin-powers-activate.html">Real SQL Guy</a></li>
<li><a href="https://www.microsoft.com/download/en/details.aspx?id=15155">SyncToy</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/hiXVCsAOHmg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2011/10/synctoy-ssmstools/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2011/10/synctoy-ssmstools/</feedburner:origLink></item>
		<item>
		<title>Get All SESSIONPROPERTY Values for Your Session</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/jvvNf06seAI/</link>
		<comments>http://www.erichumphrey.com/2011/08/sessionproperty/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 20:26:45 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=238</guid>
		<description><![CDATA[As a follow-up to my SERVERPROPERTY() post, this is a quick script to grab all the SESSIONPROPERTY() values from your current session in a table. Useful when you forget what the propertyname options are. Properties obtained from http://msdn.microsoft.com/en-us/library/ms175001.aspx. DECLARE @props TABLE &#40;propertyname sysname PRIMARY KEY&#41; INSERT INTO @props&#40;propertyname&#41; SELECT 'ANSI_NULLS' UNION ALL SELECT 'ANSI_PADDING' UNION ALL [...]]]></description>
				<content:encoded><![CDATA[<p>As a follow-up to my <a title="Get all SERVERPROPERTY values for SQL Server" href="http://www.erichumphrey.com/2011/04/serverproperty/">SERVERPROPERTY() post</a>, this is a quick script to grab all the SESSIONPROPERTY() values from your current session in a table. Useful when you forget what the propertyname options are. Properties obtained from <a href="http://msdn.microsoft.com/en-us/library/ms175001.aspx">http://msdn.microsoft.com/en-us/library/ms175001.aspx</a>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">DECLARE</span> @props <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#40;</span>propertyname sysname <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @props<span style="color: #808080;">&#40;</span>propertyname<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'ANSI_NULLS'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'ANSI_PADDING'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'ANSI_WARNINGS'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'ARITHABORT'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'CONCAT_NULL_YIELDS_ NULL'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'NUMERIC_ROUNDABORT'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'QUOTED_IDENTIFIER'</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span> propertyname, <span style="color: #FF00FF;">SESSIONPROPERTY</span><span style="color: #808080;">&#40;</span>propertyname<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">FROM</span> @props</pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/jvvNf06seAI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2011/08/sessionproperty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2011/08/sessionproperty/</feedburner:origLink></item>
		<item>
		<title>Dallas Tech Fest – Demo Files for SQL Server CLR: An Introduction</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/Kq3gx1w7X9g/</link>
		<comments>http://www.erichumphrey.com/2011/08/dallas-tech-fest-demo-files-for-sql-server-clr-an-introduction/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 18:00:27 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[clr]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[speaking]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=231</guid>
		<description><![CDATA[Demo files from my presentation at Dallas Tech Fest 2011. SQL Server CLR &#8211; An Introduction &#8211; Dallas Tech Fest 2011 *Updated 8/13: presentation with link to the MCM Readiness Video on SQLCLR]]></description>
				<content:encoded><![CDATA[<p>Demo files from my presentation at Dallas Tech Fest 2011.</p>
<p><a href="http://www.erichumphrey.com/wp-content/uploads/2011/08/SQL-Server-CLR-An-Introduction1.zip">SQL Server CLR &#8211; An Introduction &#8211; Dallas Tech Fest 2011</a></p>
<p><strong>*Updated 8/13:</strong> presentation with link to the MCM Readiness Video on SQLCLR</p>
<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/Kq3gx1w7X9g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2011/08/dallas-tech-fest-demo-files-for-sql-server-clr-an-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2011/08/dallas-tech-fest-demo-files-for-sql-server-clr-an-introduction/</feedburner:origLink></item>
		<item>
		<title>Prevent SQL Logins from using SSMS … or any other app</title>
		<link>http://feedproxy.google.com/~r/EricHumphrey/~3/a2lcb7MS8W4/</link>
		<comments>http://www.erichumphrey.com/2011/06/prevent-sql-logins-from-using-ssms/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 02:20:59 +0000</pubDate>
		<dc:creator>lotsahelp</dc:creator>
				<category><![CDATA[dba]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql triggers]]></category>

		<guid isPermaLink="false">http://www.erichumphrey.com/?p=222</guid>
		<description><![CDATA[In a continuation of my previous LOGON TRIGGER post. A downside to SQL logins is that anyone with the username / password combination can login as that user. This prevents us from knowing who truly logged in and performed some action. It is possible to trace and log everything by IP address and correlate back [...]]]></description>
				<content:encoded><![CDATA[<p><em>In a continuation of my previous <a title="Have SQL Demand Application Identification" href="http://www.erichumphrey.com/2009/11/have-sql-demand-application-identification/">LOGON TRIGGER post</a>.</em></p>
<p>A downside to SQL logins is that anyone with the username / password combination can login as that user. This prevents us from knowing who truly logged in and performed some action. It is possible to trace and log everything by IP address and correlate back to that.</p>
<p>Another downside is these accounts are usually service accounts, at least in our environment. These SQL logins may have more permissions than they should because they may be part of a vendors product, and the vendor&#8217;s app requires them to have sysadmin on the server. We have an issue with some of our users logging in as these SQL logins and running queries or manipulating data that they shouldn&#8217;t be.</p>
<p>So how can we allow the login to still exist, but deny normal users from logging in under those credentials? There&#8217;s a few different ways, one could be isolating these users to specific endpoints that would allow only that user from a given ip range. Another option, and the one that made sense here, was to use a LOGON TRIGGER. This allows us a great amount of flexibility on deciding when to prevent a connection from happening.</p>
<p>In this case, we wanted any SQL login using Management Studio to be denied access. Any of the other apps that log in with this account will still work. This includes SqlCmd, Access, etc. Our main problem, though, were devs coming in under SSMS. We also wanted to log any login attempts using this method.</p>
<p>This script creates a logging table in our management database (T1001), creates a view to make things nicer then creates the logon trigger to reject any connections that match our criteria.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">--------------------------------------------------------------------------------</span>
<span style="color: #008080;">-- Create table to hold rejected login attempts</span>
<span style="color: #008080;">--------------------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">USE</span> T1001;
GO
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> T1001.<span style="color: #202020;">SQLTrace</span>.<span style="color: #202020;">loginData</span> <span style="color: #808080;">&#40;</span>
	id <span style="color: #0000FF;">INT</span> <span style="color: #0000FF;">IDENTITY</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span>,
	<span style="color: #0000FF;">data</span> XML,
	program_name sysname
<span style="color: #808080;">&#41;</span>
GO
&nbsp;
<span style="color: #008080;">--------------------------------------------------------------------------------</span>
<span style="color: #008080;">-- Create view to make querying the table a little nicer</span>
<span style="color: #008080;">--------------------------------------------------------------------------------</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">VIEW</span> SQLTrace.<span style="color: #202020;">loginDataView</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">SELECT</span> id
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/EventType)[1]'</span>, <span style="color: #FF0000;">'sysname'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> EventType
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/PostTime)[1]'</span>, <span style="color: #FF0000;">'datetime'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> PostTime
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/SPID)[1]'</span>, <span style="color: #FF0000;">'int'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> SPID
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/ServerName)[1]'</span>, <span style="color: #FF0000;">'nvarchar(257)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> ServerName
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/LoginName)[1]'</span>, <span style="color: #FF0000;">'sysname'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> LoginName
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/LoginType)[1]'</span>, <span style="color: #FF0000;">'sysname'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> LoginType
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/SID)[1]'</span>, <span style="color: #FF0000;">'nvarchar(85)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> SID
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/ClientHost)[1]'</span>, <span style="color: #FF0000;">'sysname'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> ClientHost
      ,<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/IsPooled)[1]'</span>, <span style="color: #FF0000;">'bit'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> IsPooled
      ,program_name
<span style="color: #0000FF;">FROM</span> SQLTrace.<span style="color: #202020;">loginData</span>
GO
&nbsp;
<span style="color: #008080;">--------------------------------------------------------------------------------</span>
<span style="color: #008080;">-- Create logon trigger</span>
<span style="color: #008080;">--------------------------------------------------------------------------------</span>
<span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>master<span style="color: #808080;">&#93;</span>;
GO
&nbsp;
<span style="color: #008080;">/****** Object: DdlTrigger [Deny_SQLLogin_SSMS_Trigger] ******/</span>
<span style="color: #0000FF;">IF</span> <span style="color: #808080;">EXISTS</span><span style="color: #808080;">&#40;</span>
	<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> master.<span style="color: #202020;">sys</span>.<span style="color: #202020;">server_triggers</span>
	<span style="color: #0000FF;">WHERE</span> parent_class_desc <span style="color: #808080;">=</span> <span style="color: #FF0000;">'SERVER'</span>
		<span style="color: #808080;">AND</span> name <span style="color: #808080;">=</span> N<span style="color: #FF0000;">'Deny_SQLLogin_SSMS_Trigger'</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TRIGGER</span> <span style="color: #808080;">&#91;</span>Deny_SQLLogin_SSMS_Trigger<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">ON</span> <span style="color: #808080;">ALL</span> SERVER
GO
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TRIGGER</span> Deny_SQLLogin_SSMS_Trigger
<span style="color: #0000FF;">ON</span> <span style="color: #808080;">ALL</span> SERVER <span style="color: #0000FF;">WITH</span> <span style="color: #0000FF;">EXECUTE</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF0000;">'sa'</span>
<span style="color: #0000FF;">FOR</span> LOGON
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
<span style="color: #0000FF;">DECLARE</span> @<span style="color: #0000FF;">data</span> XML
<span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">data</span> <span style="color: #808080;">=</span> EVENTDATA<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @AppName sysname
       ,@LoginName sysname
       ,@LoginType sysname
<span style="color: #0000FF;">SELECT</span> @AppName <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>program_name<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> sys.<span style="color: #202020;">dm_exec_sessions</span>
<span style="color: #0000FF;">WHERE</span> session_id <span style="color: #808080;">=</span> @<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/SPID)[1]'</span>, <span style="color: #FF0000;">'int'</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span> @LoginName <span style="color: #808080;">=</span> @<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/LoginName)[1]'</span>, <span style="color: #FF0000;">'sysname'</span><span style="color: #808080;">&#41;</span>
      ,@LoginType <span style="color: #808080;">=</span> @<span style="color: #0000FF;">data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(/EVENT_INSTANCE/LoginType)[1]'</span>, <span style="color: #FF0000;">'sysname'</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">IF</span> @AppName <span style="color: #808080;">LIKE</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Microsoft SQL Server Management Studio%'</span><span style="color: #808080;">&#41;</span> <span style="color: #008080;">--If it's SSMS</span>
   <span style="color: #808080;">AND</span> @LoginName <span style="color: #808080;">&amp;</span>lt;<span style="color: #808080;">&amp;</span>gt; <span style="color: #FF0000;">'sa'</span>
   <span style="color: #808080;">AND</span> @LoginType <span style="color: #808080;">=</span> <span style="color: #FF0000;">'SQL Login'</span> <span style="color: #008080;">--('SQL Login' | 'Windows (NT) Login')</span>
<span style="color: #0000FF;">BEGIN</span>
    <span style="color: #0000FF;">ROLLBACK</span>; <span style="color: #008080;">--Disconnect the session</span>
&nbsp;
    <span style="color: #008080;">--Log the exception to our table</span>
    <span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> T1001.<span style="color: #202020;">SQLTrace</span>.<span style="color: #202020;">loginData</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">data</span>, program_name<span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span>@<span style="color: #0000FF;">data</span>, @AppName<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">END</span>
&nbsp;
<span style="color: #0000FF;">END</span>;
GO</pre></td></tr></table></div>

<p>Don&#8217;t forget to create a job to purge historical log data at sufficient intervals for you.</p>
<img src="http://feeds.feedburner.com/~r/EricHumphrey/~4/a2lcb7MS8W4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.erichumphrey.com/2011/06/prevent-sql-logins-from-using-ssms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.erichumphrey.com/2011/06/prevent-sql-logins-from-using-ssms/</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

 Served from: www.erichumphrey.com @ 2013-05-14 09:19:51 by W3 Total Cache -->
