<?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>SQL Server related thoughts</title>
	<atom:link href="http://underthefold.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://underthefold.org</link>
	<description>UndertheFold - There is always a lot to learn</description>
	<lastBuildDate>Sun, 03 Jan 2010 23:09:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SSIS syncing databases between like servers</title>
		<link>http://underthefold.org/2010/01/03/ssis-syncing-databases-between-like-servers/</link>
		<comments>http://underthefold.org/2010/01/03/ssis-syncing-databases-between-like-servers/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 23:09:16 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[2008]]></category>
		<category><![CDATA[ssis]]></category>

		<guid isPermaLink="false">http://underthefold.org/?p=44</guid>
		<description><![CDATA[SSIS package to Sync databases between “like” environments, for instance production and test or acceptance.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">SSIS package to Sync databases between “like” environments, for instance production and test or acceptance.</p>
<p style="text-align: justify;">This package was created in VS2008 and may have functionality only available in 2008 but will work against SQL2005 servers</p>
<p style="text-align: justify;">There is some reliance that the environments will be the same – drive letters, file locations. Users are not synced as part of this package as generally these will be static (hopefully you are using groups) The job uses the admin UNC paths so the package needs to be run with administrative credentials of both servers or shares will need to be created with the appropriate permissions.</p>
<ol style="text-align: justify;">
<li>The package first queries msdb on the source server and retrieves the paths of the last full backups.</li>
<li>It passes the database name, path and full unc path into a foreach loop container.</li>
<li>The file system task copies the backup to the path defined in the FullDestPath variable</li>
<li>An execute SQL task sets the database (if it exists) to single user</li>
<li>An execute SQL task restores the database using the full admin unc path of step 3 – This could be changed to a share to allow the process to run with less privileges</li>
<li>The loop completes this for all non system or reportserver databases (this is defined in the sql script in step 2)</li>
<li>Success email is sent on completion</li>
<li>There is also an On error event handler at the root of the package that emails any package failure</li>
</ol>
<h2 style="text-align: justify;">Package Overview</h2>
<p style="padding-left: 60px; text-align: justify;"><img class="alignnone" title="1" src="http://underthefold.org/wp-content/uploads/2010/01/1.jpg" alt="" width="688" height="624" /></p>
<ol style="text-align: justify;">
<li>
<h2>Parameters</h2>
<ol>
<li><a href="http://underthefold.org/wp-content/uploads/2010/01/2.jpg"><img class="alignnone size-full wp-image-46" title="2" src="http://underthefold.org/wp-content/uploads/2010/01/2.jpg" alt="" width="616" height="327" /></a></li>
<li><a href="http://underthefold.org/wp-content/uploads/2010/01/3.jpg"><img class="alignnone size-full wp-image-47" title="3" src="http://underthefold.org/wp-content/uploads/2010/01/3.jpg" alt="" width="248" height="72" /></a></li>
</ol>
</li>
<li>
<h2>Retrieve Database name and last full backup Path</h2>
<ol>
<li>Create an Execute T-SQL Statement task  against your Source server (msdb database)</li>
</ol>
</li>
</ol>
<blockquote style="text-align: justify;">
<ol>
<li>With a full result set to an Object data type – here I have used rowset1</li>
<li><a href="http://underthefold.org/wp-content/uploads/2010/01/4.jpg"><img class="alignnone size-full wp-image-48" title="4" src="http://underthefold.org/wp-content/uploads/2010/01/4.jpg" alt="" width="534" height="289" /></a></li>
<li>Use the SQL statement below,</li>
</ol>
<pre style="padding-left: 60px;"><span style="color: blue;">WITH    </span><span style="color: black;">BACKUPS
   </span><span style="color: blue;">AS </span><span style="color: gray;">(
 </span><span style="color: blue;">SELECT
    </span><span style="color: black;">a.Server
    </span><span style="color: gray;">,</span><span style="color: black;">a.database_name
    </span><span style="color: gray;">,</span><span style="color: black;">B.physical_device_name
  </span><span style="color: blue;">FROM
  </span><span style="color: gray;">(
  </span><span style="color: blue;">SELECT
     </span><span style="color: magenta;">CONVERT</span><span style="color: gray;">(</span><span style="color: blue;">NVARCHAR</span><span style="color: gray;">(</span><span style="color: blue;">MAX</span><span style="color: gray;">), </span><span style="color: magenta;">SERVERPROPERTY</span><span style="color: gray;">(</span><span style="color: red;">'Servername'</span><span style="color: gray;">)) </span><span style="color: blue;">AS </span><span style="color: black;">Server
     </span><span style="color: gray;">,</span><span style="color: black;">msdb.dbo.backupset.database_name
     </span><span style="color: gray;">,</span><span style="color: blue;">MAX</span><span style="color: gray;">(</span><span style="color: black;">msdb.dbo.backupset.backup_finish_date</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">last_db_backup_date
   </span><span style="color: blue;">FROM
     </span><span style="color: black;">msdb.dbo.backupmediafamily
     </span><span style="color: blue;">INNER JOIN </span><span style="color: black;">msdb.dbo.backupset
     </span><span style="color: blue;">ON </span><span style="color: black;">msdb.dbo.backupmediafamily.media_set_id </span><span style="color: blue;">= </span><span style="color: black;">msdb.dbo.backupset.media_set_id
   </span><span style="color: blue;">WHERE
     </span><span style="color: black;">msdb..backupset.type </span><span style="color: blue;">= </span><span style="color: red;">'D'
    </span><span style="color: gray;">AND </span><span style="color: black;">msdb.dbo.backupset.database_name </span><span style="color: gray;">NOT </span><span style="color: blue;">IN </span><span style="color: gray;">(
    </span><span style="color: red;">'Master'</span><span style="color: gray;">, </span><span style="color: red;">'msdb'</span><span style="color: gray;">, </span><span style="color: red;">'model'</span><span style="color: gray;">, </span><span style="color: red;">'reportserver'</span><span style="color: gray;">,
    </span><span style="color: red;">'reportservertempdb' </span><span style="color: gray;">)
   </span><span style="color: blue;">GROUP BY
     </span><span style="color: black;">msdb.dbo.backupset.database_name
  </span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">A
    </span><span style="color: magenta;">LEFT </span><span style="color: blue;">JOIN </span><span style="color: gray;">(
  </span><span style="color: blue;">SELECT
     </span><span style="color: magenta;">CONVERT</span><span style="color: gray;">(</span><span style="color: blue;">CHAR</span><span style="color: gray;">(</span><span style="color: black;">100</span><span style="color: gray;">), </span><span style="color: magenta;">SERVERPROPERTY</span><span style="color: gray;">(</span><span style="color: red;">'Servername'</span><span style="color: gray;">)) </span><span style="color: blue;">AS </span><span style="color: black;">Server
     </span><span style="color: gray;">,</span><span style="color: black;">msdb.dbo.backupset.database_name
     </span><span style="color: gray;">,</span><span style="color: black;">msdb.dbo.backupset.backup_finish_date
     </span><span style="color: gray;">,</span><span style="color: black;">msdb.dbo.backupmediafamily.physical_device_name
   </span><span style="color: blue;">FROM
     </span><span style="color: black;">msdb.dbo.backupmediafamily
     </span><span style="color: blue;">INNER JOIN </span><span style="color: black;">msdb.dbo.backupset
     </span><span style="color: blue;">ON </span><span style="color: black;">msdb.dbo.backupmediafamily.media_set_id </span><span style="color: blue;">= </span><span style="color: black;">msdb.dbo.backupset.media_set_id
   </span><span style="color: blue;">WHERE
     </span><span style="color: black;">msdb..backupset.type </span><span style="color: blue;">= </span><span style="color: red;">'D'
  </span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">B
    </span><span style="color: blue;">ON </span><span style="color: black;">A.[server] </span><span style="color: blue;">= </span><span style="color: black;">B.[server]
   </span><span style="color: gray;">AND </span><span style="color: black;">A.[database_name] </span><span style="color: blue;">= </span><span style="color: black;">B.[database_name]
   </span><span style="color: gray;">AND </span><span style="color: black;">A.[last_db_backup_date] </span><span style="color: blue;">= </span><span style="color: black;">B.[backup_finish_date]
 </span><span style="color: gray;">)
</span><span style="color: blue;">SELECT
   </span><span style="color: black;">[database_name]
   </span><span style="color: gray;">,</span><span style="color: black;">[physical_device_name] </span><span style="color: blue;">AS </span><span style="color: black;">databasePath
   </span><span style="color: gray;">,</span><span style="color: red;">'\\' </span><span style="color: gray;">+ </span><span style="color: black;">[Server] </span><span style="color: gray;">+ </span><span style="color: red;">'\' </span><span style="color: gray;">+ </span><span style="color: magenta;">REPLACE</span><span style="color: gray;">(</span><span style="color: black;">[physical_device_name]</span><span style="color: gray;">, </span><span style="color: red;">':'</span><span style="color: gray;">, </span><span style="color: red;">'$'</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">FullSourcePath
 </span><span style="color: blue;">FROM
   </span><span style="color: black;">[BACKUPS]

   </span></pre>
<ol>
<li>Set your result set</li>
<li><a href="http://underthefold.org/wp-content/uploads/2010/01/5.jpg"><img class="alignnone size-full wp-image-49" title="5" src="http://underthefold.org/wp-content/uploads/2010/01/5.jpg" alt="" width="393" height="43" /></a></li>
</ol>
</blockquote>
<ol style="text-align: justify;">
<li>
<h2>Use a ForEach Loop Container</h2>
<ol>
<li>Set the enumerator to Foreach ADO Enumerator with your object source as your object variable .</li>
</ol>
</li>
</ol>
<p style="padding-left: 90px; text-align: justify;"><a href="http://underthefold.org/wp-content/uploads/2010/01/6.jpg"><img class="alignnone size-full wp-image-50" title="6" src="http://underthefold.org/wp-content/uploads/2010/01/6.jpg" alt="" width="416" height="318" /></a></p>
<ol style="text-align: justify;">
<li>
<ol>
<li>Map your variables</li>
</ol>
</li>
</ol>
<p style="padding-left: 90px; text-align: justify;"><img class="alignnone size-full wp-image-51" title="7" src="http://underthefold.org/wp-content/uploads/2010/01/7.jpg" alt="" width="483" height="103" /></p>
<ol style="text-align: justify;">
<li>
<h2>Add a File System Task</h2>
<ol>
<li>Configure with your source and destination variable and a Copy File operation</li>
</ol>
</li>
</ol>
<p style="padding-left: 90px; text-align: justify;"><a href="http://underthefold.org/wp-content/uploads/2010/01/8.jpg"><img class="alignnone size-full wp-image-52" title="8" src="http://underthefold.org/wp-content/uploads/2010/01/8.jpg" alt="" width="400" height="205" /></a></p>
<ol style="text-align: justify;">
<li>
<ol>
<li></li>
</ol>
</li>
</ol>
<ol style="text-align: justify;">
<li>
<h2>Create T-SQL Statement Task against your destination server (master database)</h2>
</li>
</ol>
<pre style="padding-left: 120px; text-align: justify;"><span style="color: blue;">DECLARE </span><span style="color: #434343;">@databaseName </span><span style="color: blue;">VARCHAR</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">)
</span><span style="color: blue;">SET </span><span style="color: #434343;">@databaseName </span><span style="color: blue;">= </span><span style="color: black;">?
</span><span style="color: blue;">IF  </span><span style="color: gray;">EXISTS
(</span><span style="color: blue;">SELECT </span><span style="color: black;">name </span><span style="color: blue;">FROM </span><span style="color: black;">sys.databases </span><span style="color: blue;">WHERE </span><span style="color: black;">name </span><span style="color: blue;">= </span><span style="color: #434343;">@databaseName</span><span style="color: gray;">)
</span><span style="color: blue;">EXEC</span><span style="color: gray;">(</span><span style="color: red;">'ALTER DATABASE ' </span><span style="color: gray;">+ </span><span style="color: #434343;">@databaseName </span><span style="color: gray;">+  </span><span style="color: red;">' SET SINGLE_USER WITH ROLLBACK IMMEDIATE'</span><span style="color: gray;">)
</span></pre>
<blockquote style="text-align: justify;">
<blockquote>
<blockquote>
<ol>
<li>Map your parameter like this</li>
</ol>
<p><a href="http://underthefold.org/wp-content/uploads/2010/01/9.jpg"><img class="alignnone size-full wp-image-53" title="9" src="http://underthefold.org/wp-content/uploads/2010/01/9.jpg" alt="" width="651" height="49" /></a></p></blockquote>
</blockquote>
</blockquote>
<ol style="text-align: justify;">
<li>
<h2>Create T-SQL Statement Task against your destination server (master database)</h2>
</li>
</ol>
<pre style="padding-left: 120px; text-align: justify;"><span style="color: blue;">DECLARE </span><span style="color: #434343;">@databaseName </span><span style="color: blue;">VARCHAR</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">)
</span><span style="color: blue;">DECLARE </span><span style="color: #434343;">@FullDestPath </span><span style="color: blue;">VARCHAR</span><span style="color: gray;">(</span><span style="color: blue;">MAX</span><span style="color: gray;">)
    </span><span style="color: blue;">SET </span><span style="color: #434343;">@databasename </span><span style="color: blue;">= </span><span style="color: black;">?
    </span><span style="color: blue;">SET </span><span style="color: #434343;">@FullDestPath </span><span style="color: blue;">= </span><span style="color: black;">?
</span><span style="color: blue;">EXEC</span><span style="color: gray;">(
        </span><span style="color: red;">'RESTORE DATABASE ' </span><span style="color: gray;">+ </span><span style="color: #434343;">@databaseName </span><span style="color: gray;">+ </span><span style="color: red;">' FROM DISK =
N''' </span><span style="color: gray;">+  </span><span style="color: #434343;">@FullDestPath </span><span style="color: gray;">+ </span><span style="color: red;">'''WITH RECOVERY, FILE = 1, NOUNLOAD, REPLACE, STATS = 10'</span><span style="color: gray;">)
</span><span style="color: black;">GO
</span></pre>
<ol style="padding-left: 90px; text-align: justify;">
<li>Map your parameters like this</li>
</ol>
<p style="padding-left: 120px; text-align: justify;"><a href="http://underthefold.org/wp-content/uploads/2010/01/10.jpg"><img class="alignnone size-full wp-image-54" title="10" src="http://underthefold.org/wp-content/uploads/2010/01/10.jpg" alt="" width="618" height="67" /></a></p>
<ol style="text-align: justify;">
<li>
<h2>Add a Send Mail  task using the following expressions</h2>
</li>
</ol>
<p style="padding-left: 120px; text-align: justify;"><a href="http://underthefold.org/wp-content/uploads/2010/01/11.jpg"><img class="alignnone size-full wp-image-55" title="11" src="http://underthefold.org/wp-content/uploads/2010/01/11.jpg" alt="" width="671" height="96" /></a></p>
<p style="padding-left: 120px; text-align: justify;">
<ol style="text-align: justify;">
<li>
<h2>On the even Handlers tab</h2>
</li>
</ol>
<blockquote style="padding-left: 60px; text-align: justify;">
<ol>
<li>Create an onError handler at the <span style="text-decoration: underline;">root</span> of the package</li>
</ol>
<p><a href="http://underthefold.org/wp-content/uploads/2010/01/12.jpg"><img class="alignnone size-full wp-image-56" title="12" src="http://underthefold.org/wp-content/uploads/2010/01/12.jpg" alt="" width="707" height="327" /></a></p>
<ul>
<li> Add a Send mail task with the following expressions</li>
</ul>
</blockquote>
<p style="padding-left: 120px; text-align: justify;"><a href="http://underthefold.org/wp-content/uploads/2010/01/13.jpg"><img class="alignnone size-full wp-image-57" title="13" src="http://underthefold.org/wp-content/uploads/2010/01/13.jpg" alt="" width="824" height="119" /></a></p>
<ol style="text-align: justify;">
<li>I also create a config file to allow the package to be used in different locations without editing the package itself
<ol>
<li>databaseName – value</li>
<li>DestPath – value ( this is either a share or UNC – it does NOT contain the server name – it uses the DestServer variable so it should be in the format “C$\sql\backups” or “mybackupshare”</li>
<li>DestServer – value</li>
<li>SMTPFailureTo – value</li>
<li>SMTPFrom – value</li>
<li>SMTPServer – value</li>
<li>SMTPSuccessTo – value</li>
<li>SourceServer &#8211; value</li>
</ol>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2010/01/03/ssis-syncing-databases-between-like-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KB970892 failing and leaving your SQL service stopped?</title>
		<link>http://underthefold.org/2009/12/19/kb970892-failing-and-leaving-your-sql-service-stopped/</link>
		<comments>http://underthefold.org/2009/12/19/kb970892-failing-and-leaving-your-sql-service-stopped/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:23:41 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[2005]]></category>
		<category><![CDATA[kb970892]]></category>
		<category><![CDATA[sp3]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=27</guid>
		<description><![CDATA[Finding your SQL service not running is never a recipe for a good day, Recently I&#8217;ve seen this happen on numerous occasions when KB970892 tries to apply  to a SQL 2005 SP3 9.0.4035 box -with the System databases moved to a different drive. It appears the patch just looks in the system database data folder [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Finding your SQL service not running is never a recipe for a good day, Recently I&#8217;ve seen this happen on numerous occasions when KB970892 tries to apply  to a SQL 2005 SP3 9.0.4035 box -with the System databases moved to a different drive. It appears the patch just looks in the system database data folder for the mssqlsystemresource and distmdl mdf&#8217;s &amp; ldf&#8217;s. Not in the orginal install folder.</p>
<p>I filed a bug <a title="CONNECT" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=509310">here</a></p>
<p>As a workaround you can manually copy the mssqlsystemresource and distmdl mdf&#8217;s &amp; ldf&#8217;s to the data folder your system database mdf&#8217;s are in</p></div>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/kb970892-failing-and-leaving-your-sql-service-stopped/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Knight&#8217;s 24-Hour Trainer: Microsoft SQL Server 2008 Integration Services</title>
		<link>http://underthefold.org/2009/12/19/knights-24-hour-trainer-microsoft-sql-server-2008-integration-services/</link>
		<comments>http://underthefold.org/2009/12/19/knights-24-hour-trainer-microsoft-sql-server-2008-integration-services/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:22:52 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[ssis]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=25</guid>
		<description><![CDATA[I buy a lot of technical books, I have at least 10 SQL 2008 books, I normally go for the professional versions and I actually read them. The trouble is there huge! They are a pain to carry round and just plain awkward to read. I usually end up using a stand as most technical [...]]]></description>
			<content:encoded><![CDATA[<p>I buy a lot of technical books, I have at least 10 SQL 2008 books, I normally go for the professional versions and I actually read them. The trouble is there huge! They are a pain to carry round and just plain awkward to read. I usually end up using a stand as most technical books have walkthrough’s or demos &#8211; try holding up one of those books or even prop them up while you are trying to type. This means I generally only read in the evenings at home. When I saw the <a href="http://www.amazon.com/Knights-24-Hour-Trainer-Integration-Programmer/dp/0470496924/ref=sr_1_1?ie=UTF8&amp;qid=1256067932&amp;sr=8-1">24 hour trainer</a> book I figured here is a good sized book I can carry around and actually read.</p>
<p>I have always struggled with SSIS, it looks cool and seems friendly but whenever I tried to do anything I couldn’t figure out my arse from my elbow.  I have a need to sync databases, cubes, packages etc between environments. I figured it would be a cool to try and do it in SSIS. Solving my problem and increasing my knowledge at the same time.</p>
<p>I originally started watching the dvd demos and following along. Then I switched to the book – don’t get me wrong it was great to see the packages being constructed – (nice to see it instead of following on from a book). But the book presented the “try it” with hints so you could attempt to build the package without just mimicking the demo. Also the DVD was not the greatest quality – I found it hard to see some of the scripts, when I didn’t have the book in front of me.</p>
<p>I named all my packages as the task that was being covered ionstead of chapter name as suggested because I feel like I can refer back to them easily- I did all my script tasks in C# &#8211; the book was VB only.</p>
<p>Overall I found this to be an excellent book, I really learnt a lot. I definitely appreciate the smaller size.</p>
<p>Note: Authors – how about breaking your books into series to keep the size down.</p>
<p>I’m going to attempt to build my Environment Sync – if it works I’ll post some details</p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/knights-24-hour-trainer-microsoft-sql-server-2008-integration-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PASS, SQL Server and Virtulization</title>
		<link>http://underthefold.org/2009/12/19/pass-sql-server-and-virtulization/</link>
		<comments>http://underthefold.org/2009/12/19/pass-sql-server-and-virtulization/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:22:26 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=23</guid>
		<description><![CDATA[Got questions? come to the free Breakfast session at the PASS Summit]]></description>
			<content:encoded><![CDATA[<p>Got questions? come to the <a title="FREE!" href="http://www.sqlpass.org/Events/ctl/ViewEvent/mid/521.aspx?ID=247">free Breakfast session</a> at the <a title="PASS Summit" href="http://summit2009.sqlpass.org/">PASS Summit</a></p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/pass-sql-server-and-virtulization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL 2008 Reporting services &#8211; ReportServerStorageException: An error occurred within the report server database. This may be due to a connection failure, timeout or low disk condition within the database.</title>
		<link>http://underthefold.org/2009/12/19/sql-2008-reporting-services-reportserverstorageexception-an-error-occurred-within-the-report-server-database-this-may-be-due-to-a-connection-failure-timeout-or-low-disk-condition-within-the-datab/</link>
		<comments>http://underthefold.org/2009/12/19/sql-2008-reporting-services-reportserverstorageexception-an-error-occurred-within-the-report-server-database-this-may-be-due-to-a-connection-failure-timeout-or-low-disk-condition-within-the-datab/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:22:03 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[2008]]></category>
		<category><![CDATA[reportin services]]></category>
		<category><![CDATA[sp1]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=21</guid>
		<description><![CDATA[Had some strange error accessing the history tab and some of the other tabs of some scheduled reports in SQL 2008 SP1. With a misleading error &#8220;   ReportServerStorageException: An error occurred within the report server database.  This may be due to a connection failure, timeout or low disk condition within the database.&#8221; I at one [...]]]></description>
			<content:encoded><![CDATA[<p>Had some strange error accessing the history tab and some of the other tabs of some scheduled reports in SQL 2008 SP1.</p>
<p>With a misleading error &#8220;   ReportServerStorageException: An error occurred within the report server database.  This may be due to a connection failure, timeout or low disk condition within the database.&#8221;</p>
<p>I at one time restored these databases after a server reinstall from a failed SP1 upgrade. Everything worked for the most part but these odd errors on some reports kept happening.</p>
<p>This error pointed me in the right direction when expanding the schedules tab in SSMS connected with Reporting services</p>
<p>EXECUTE permission denied on object &#8216;xp_sqlagent_notify&#8217;, database &#8216;mssqlsystemresource&#8217;, schema &#8216;sys&#8217;.</p>
<p>To resolve this ensure the rsexecrole exists in Master, MSDB, ReportServer &amp; ReportServerTempDB</p>
<p>then run the following script</p>
<p><code><span style="color: blue;">USE </span><span style="color: black;">master<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">master.dbo.</span><span style="color: darkred;">xp_sqlagent_notify </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">master.dbo.</span><span style="color: darkred;">xp_sqlagent_enum_jobs </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">master.dbo.</span><span style="color: darkred;">xp_sqlagent_is_starting </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO</p>
<p></span><span style="color: blue;">USE </span><span style="color: black;">msdb<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_help_category </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_add_category </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_add_job </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_add_jobserver </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_add_jobstep </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_add_jobschedule </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_help_job </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_delete_job </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_help_jobschedule </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT EXECUTE ON </span><span style="color: black;">msdb.dbo.</span><span style="color: darkred;">sp_verify_job_identifiers </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT SELECT ON </span><span style="color: black;">msdb.dbo.sysjobs </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span><span style="color: blue;">GRANT SELECT ON </span><span style="color: black;">msdb.dbo.syscategories </span><span style="color: blue;">TO </span><span style="color: black;">RSExecRole<br />
GO<br />
</span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/sql-2008-reporting-services-reportserverstorageexception-an-error-occurred-within-the-report-server-database-this-may-be-due-to-a-connection-failure-timeout-or-low-disk-condition-within-the-datab/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL 2000 and Vsphere 4 drivers</title>
		<link>http://underthefold.org/2009/12/19/sql-2000-and-vsphere-4-drivers/</link>
		<comments>http://underthefold.org/2009/12/19/sql-2000-and-vsphere-4-drivers/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:21:17 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[VMWare]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[2000]]></category>
		<category><![CDATA[vsphere]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=19</guid>
		<description><![CDATA[Looks like an old bug came back in VSPhere4 concerning SQL 2000 &#8211; When you update the VM tools MSVCP71.dll goes missing and the SQL service will not start. Version 4.0.0, build 164009 This can be resolved by placing the file back into the %SYSTEMROOT%\System32 folder]]></description>
			<content:encoded><![CDATA[<p>Looks like an old bug came back in VSPhere4 concerning SQL 2000 &#8211; When you update the VM tools MSVCP71.dll goes missing and the SQL service will not start.</p>
<p>Version 4.0.0, build 164009</p>
<p>This can be resolved by placing the file back into the %SYSTEMROOT%\System32 folder</p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/sql-2000-and-vsphere-4-drivers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The application-specific permission settings do not grant Local Launch permission for the COM Server application with CLSID {46063B1E-BE4A-4014-8755-5B377CD462FC}</title>
		<link>http://underthefold.org/2009/12/19/the-application-specific-permission-settings-do-not-grant-local-launch-permission-for-the-com-server-application-with-clsid-46063b1e-be4a-4014-8755-5b377cd462fc/</link>
		<comments>http://underthefold.org/2009/12/19/the-application-specific-permission-settings-do-not-grant-local-launch-permission-for-the-com-server-application-with-clsid-46063b1e-be4a-4014-8755-5b377cd462fc/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:20:38 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=17</guid>
		<description><![CDATA[When using a domain account that is not a local administrator in SQL 2008 &#38; SP1 as the SQL Agent service account I see the error: The application-specific permission settings do not grant Local Launch permission for the COM Server application with CLSID {46063B1E-BE4A-4014-8755-5B377CD462FC} to the user *DOMAIN ACCOUNT* SID (S-1-5-21-651981998-221456604-1849977318-14822). This security permission can [...]]]></description>
			<content:encoded><![CDATA[<p>When using a domain account that is not a local administrator in SQL 2008 &amp; SP1 as the SQL Agent service account I see the error:</p>
<p><span><br />
The application-specific permission settings do not grant Local Launch permission for the COM Server application with CLSID<br />
{46063B1E-BE4A-4014-8755-5B377CD462FC}<br />
to the user *DOMAIN ACCOUNT* SID (S-1-5-21-651981998-221456604-1849977318-14822). This security permission can be modified using the Component Services administrative tool.</p>
<p>For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.</span></p>
<p>To correct this</p>
<p><span>– open com permissions<br />
Component services, computers, my computer,<br />
DCOM config, find the MSDTSServer100<br />
Properties<br />
Security<br />
Launch and Activate permissions – edit<br />
Add the local SQL AgentUser group and enable local launch and Local activation</span></p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/the-application-specific-permission-settings-do-not-grant-local-launch-permission-for-the-com-server-application-with-clsid-46063b1e-be4a-4014-8755-5b377cd462fc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More powershell SQL cmdb type stuff</title>
		<link>http://underthefold.org/2009/12/19/more-powershell-sql-cmdb-type-stuff/</link>
		<comments>http://underthefold.org/2009/12/19/more-powershell-sql-cmdb-type-stuff/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:20:04 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=15</guid>
		<description><![CDATA[I think there is a lot of potential using powershell to build a cmbd. rhyscampbell on twitter has a great post on his site Also Chad Miller cmille19 on twitter has done some great stuff with the  sqlpsx project I  am still pursuing using merge but there is definately an advantage to dropping to csv [...]]]></description>
			<content:encoded><![CDATA[<p>I think there is a lot of potential using powershell to build a cmbd.</p>
<p><a title="rhyscampbell" href="http://twitter.com/rhyscampbell">rhyscampbel</a>l on twitter has a great post on his <a href="http://www.youdidwhatwithtsql.com/auditing-your-sql-server-with-powershell/133">site</a></p>
<p>Also Chad Miller <a title="cmille19" href="http://twitter.com/cmille19">cmille19</a> on twitter has done some great stuff with the  <a href="http://sqlpsx.codeplex.com/">sqlpsx</a> project</p>
<p>I  am still pursuing using merge but there is definately an advantage to dropping to csv and then using etl in in one go.</p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/more-powershell-sql-cmdb-type-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>updated &#8211; with version check, uptime</title>
		<link>http://underthefold.org/2009/12/19/updated-with-version-check-uptime/</link>
		<comments>http://underthefold.org/2009/12/19/updated-with-version-check-uptime/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:19:32 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=13</guid>
		<description><![CDATA[I figured out how to do get variables from a query. So i added a second get-sqldata function within the loop Because i have a mixed environment i need a version check to set the sysprocess table or view -The new columns will need to be added to the merge statement in the the previous [...]]]></description>
			<content:encoded><![CDATA[<p>I figured out how to do get variables from a query. So i added a second get-sqldata function within the loop</p>
<p>Because i have a mixed environment i need a version check to set the sysprocess table or view -The new columns will need to be added to the merge statement in the the previous script and the table updated</p>
<p><code><span style="color: black;"> </span><span style="color: blue;">if </span><span style="color: gray;">(</span><span style="color: black;">$srv.Version.ToString</span><span style="color: gray;">() -</span><span style="color: black;">lt </span><span style="color: darkred;">"9.00.0000.00"</span><span style="color: gray;">)<br />
</span><span style="color: black;">{$sysprocesses </span><span style="color: blue;">= </span><span style="color: darkred;">"sysprocesses"</span><span style="color: black;">}<br />
</span><span style="color: blue;">else<br />
</span><span style="color: black;">{$sysprocesses </span><span style="color: blue;">= </span><span style="color: darkred;">"sys.sysprocesses"</span><span style="color: black;">}<br />
#Write</span><span style="color: gray;">-</span><span style="color: black;">Host $sysprocesses<br />
function Get</span><span style="color: gray;">-</span><span style="color: black;">SqlListsstarttime<br />
{<br />
Get</span><span style="color: gray;">-</span><span style="color: black;">SqlData $Server </span><span style="color: darkred;">"master"  "SELECT login_time AS Started ,DATEDIFF(DAY, login_time, CURRENT_TIMESTAMP) AS daysUptime FROM $sysprocesses where spid = 1;<br />
" </span><span style="color: gray;">| </span><span style="color: blue;">foreach </span><span style="color: black;">{$_.started</span><span style="color: gray;">,</span><span style="color: black;">$_.daysUptime} </span><span style="color: gray;">|<br />
</span><span style="color: blue;">foreach </span><span style="color: black;">{ $uptimeList.Add</span><span style="color: gray;">(</span><span style="color: darkred;">"$_"</span><span style="color: gray;">) &gt; </span><span style="color: black;">$null }<br />
}# gets time started and uptime<br />
Get</span><span style="color: gray;">-</span><span style="color: black;">SqlListsstarttime<br />
$started </span><span style="color: blue;">= </span><span style="color: black;">$uptimelist[0]<br />
$daysuptime </span><span style="color: blue;">= </span><span style="color: black;">$uptimelist[1] </span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/updated-with-version-check-uptime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell, Monitoring and the Central Management Server</title>
		<link>http://underthefold.org/2009/12/19/powershell-monitoring-and-the-central-management-server/</link>
		<comments>http://underthefold.org/2009/12/19/powershell-monitoring-and-the-central-management-server/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:18:41 +0000</pubDate>
		<dc:creator>Underthefold</dc:creator>
				<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://underthefold.net/?p=11</guid>
		<description><![CDATA[I have been looking at gathering basic information in my environment using powershell. There is some good stuff out there. I have been using the CMS server registered server function to query multiple servers but the problem is you can only query against them and not write to your CMS without using linked servers.]]></description>
			<content:encoded><![CDATA[<p><code style="font-size: 12px;"><span style="color: black;"><br />
</span><span style="color: green;">/****** Object:  Table [dbo].[ServerInfo]    Script Date: 05/29/2009 15:46:21 ******/<br />
</span><span style="color: blue;">SET </span><span style="color: black;">ANSI_NULLS </span><span style="color: blue;">ON<br />
</span><span style="color: black;">GO<br />
</span><span style="color: blue;">SET </span><span style="color: black;">QUOTED_IDENTIFIER </span><span style="color: blue;">ON<br />
</span><span style="color: black;">GO<br />
</span><span style="color: blue;">SET </span><span style="color: black;">ANSI_PADDING </span><span style="color: blue;">ON<br />
</span><span style="color: black;">GO<br />
</span><span style="color: blue;">CREATE TABLE </span><span style="color: black;">[dbo].[ServerInfo]</span><span style="color: gray;">(<br />
</span><span style="color: black;">[ServerID] [int] </span><span style="color: #434343;">IDENTITY</span><span style="color: gray;">(</span><span style="color: black;">1</span><span style="color: gray;">,</span><span style="color: black;">1</span><span style="color: gray;">) NOT NULL,<br />
</span><span style="color: black;">[LastUpdated] [datetime] </span><span style="color: gray;">NULL,<br />
</span><span style="color: black;">[Server] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[Instance] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[Version] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[Edition] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[ServicePack] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[TimeStarted] [datetime] </span><span style="color: gray;">NULL,<br />
</span><span style="color: black;">[BackupDirectory] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[defaultfile] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[defaultlog] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[installdatadirectory] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[osversion] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[physicalmemory] [int] </span><span style="color: gray;">NULL,<br />
</span><span style="color: black;">[errorlogpath] [nvarchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: blue;">CONSTRAINT </span><span style="color: black;">[PK_ServerInfo] </span><span style="color: blue;">PRIMARY KEY CLUSTERED<br />
</span><span style="color: gray;">(<br />
</span><span style="color: black;">[ServerID] </span><span style="color: blue;">ASC<br />
</span><span style="color: gray;">)</span><span style="color: blue;">WITH </span><span style="color: gray;">(</span><span style="color: black;">PAD_INDEX </span><span style="color: blue;">= OFF</span><span style="color: gray;">, </span><span style="color: black;">STATISTICS_NORECOMPUTE </span><span style="color: blue;">= OFF</span><span style="color: gray;">,</p>
<p></span><span style="color: black;">IGNORE_DUP_KEY </span><span style="color: blue;">= OFF</span><span style="color: gray;">, </span><span style="color: black;">ALLOW_ROW_LOCKS </span><span style="color: blue;">= ON</span><span style="color: gray;">, </span><span style="color: black;">ALLOW_PAGE_LOCKS </span><span style="color: blue;">= ON</span><span style="color: gray;">) </span><span style="color: blue;">ON </span><span style="color: black;">[PRIMARY]<br />
</span><span style="color: gray;">) </span><span style="color: blue;">ON </span><span style="color: black;">[PRIMARY]<br />
GO<br />
</span><span style="color: blue;">SET </span><span style="color: black;">ANSI_PADDING </span><span style="color: blue;">OFF<br />
</span><span style="color: black;">GO</p>
<p></span></code></p>
<p>I have been looking at gathering basic information in my environment using powershell. There is some good stuff out there. I have been using the CMS server registered server function to query multiple servers but the problem is you can only query against them and not write to your CMS without using linked servers.</p>
<p>So I looked at some of the projects on Codeplex  &#8211; Buck Woody&#8217;s <a title="SQLCMS" href="http://sqlcms.codeplex.com/">SQLCMS</a> got me interested in extending the CMS datawarehouse.</p>
<p><a title="CMDB" href="http://sqlserverpedia.com/wiki/CMDB">Sqlserverpedia</a> has some good info on building a CMDB and extending the CMS datawarehouse too</p>
<p>Then I took a look at Chad Millers <a title="SQLPSX" href="http://sqlpsx.codeplex.com/">SQLPSX</a> project he has written some excellent functions and has a complete Powershell &#8220;base&#8221; on codeplex. I learnt a lot from looking throught the scripts and functions.</p>
<p>Using the SQLPSX library and functions, I wrote a powershell script that queries each server in your Central Management Server by group or as a whole returning basic information like version, Service pack, default backupfolder, OS version, Memory and path location information and merges it into a table so it can be run repeatedly.</p>
<p>*use at your own risk of course <img src='http://underthefold.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>**this requires the SQLPSX library &#8211; see above</p>
<p>[void][reflection.assembly]::LoadWithPartialName(&#8220;Microsoft.SqlServer.Smo&#8221;)</p>
<p>##Point to library files</p>
<p>$scriptRoot = <strong>Split-Path</strong> (<strong>Resolve-Path</strong> $myInvocation.MyCommand.Path)</p>
<p>#. $scriptRoot\LibrarySmo.ps1</p>
<p><strong>Set-Alias</strong> Test-SqlConn $scriptRoot\Test-SqlConn.ps1</p>
<p>##Define variables</p>
<p>#CMS Server</p>
<p>$sqlServer = &#8220;YOURSERVERNAMEHERE&#8221;</p>
<p>$dbName = &#8220;msdb&#8221;</p>
<p>$ServerList = <strong>New-Object</strong> System.Collections.ArrayList</p>
<p>##CMS server Group</p>
<p>$serverGroup = &#8220;CMS SERVER GROUP NAME OR % FOR ALL&#8221;</p>
<p>##CMS database</p>
<p>$dbTARGET = &#8220;DATABASE WITH THE TABLE _SCRIPT AT THE BOTTOM&#8221;</p>
<p>##CMS Table</p>
<p>$tblServerInfo = &#8220;TABLENAME&#8221;</p>
<p>#######################</p>
<p>function Get-SqlList</p>
<p>{</p>
<p>Get-SqlData $SQLServer $dbname  &#8220;SELECT DISTINCT</p>
<p>s.server_name as server</p>
<p>FROM    dbo.sysmanagement_shared_server_groups_internal g</p>
<p>INNER JOIN dbo.sysmanagement_shared_registered_servers_internal s ON g.server_group_id = s.server_group_id</p>
<p>where   g.NAME LIKE &#8216;$serverGroup&#8217;</p>
<p>&#8221; | <strong>foreach</strong> {$_.Server} | Test-SqlConn |</p>
<p><strong>foreach</strong> { $ServerList.Add(&#8220;$_&#8221;) &gt; $null }</p>
<p>#Write-Host $ServerList</p>
<p>}# Get-SqlList</p>
<p>Get-SqlList</p>
<p>while ($ServerList.Count -gt 0)</p>
<p>{</p>
<p>$server = $ServerList[0]</p>
<p>#Launch Another Thread</p>
<p>#Write-Host $server</p>
<p>## open database connection</p>
<p>$conn = <strong>New-Object</strong> System.Data.SqlClient.SqlConnection(&#8220;Data Source=$sqlServer;</p>
<p>Initial Catalog=$dbtarget; Integrated Security=SSPI&#8221;)</p>
<p>$conn.Open()</p>
<p>$cmd = $conn.CreateCommand()</p>
<p>##read servernames and update/insert the table</p>
<p>#get-content C:\Working\SQLCMS\Powershellscripts\servers.txt | foreach {</p>
<p>#$server = $_</p>
<p>$srv = <strong>New-Object</strong> Microsoft.SqlServer.Management.Smo.Server $server</p>
<p>$lastUpdated = <strong>Get-Date</strong></p>
<p>$servername = $srv.Name</p>
<p>$instance = $srv.InstanceName</p>
<p>$version = $srv.VersionString</p>
<p>$edition = $srv.Edition</p>
<p>$ServicePack = $srv.ProductLevel</p>
<p>$BackupDirectory = $srv.BackupDirectory</p>
<p>$defaultfile = $srv.DefaultFile</p>
<p>$defaultlog = $srv.DefaultLog</p>
<p>$installdatadirectory = $srv.InstallDataDirectory</p>
<p>$osversion = $srv.OSVersion</p>
<p>$physicalmemory = $srv.PhysicalMemory</p>
<p>$errorlogpath = $srv.ErrorLogPath</p>
<p>$cmd.CommandText = &#8221;</p>
<p>MERGE $tblServerInfo AS target</p>
<p>USING (VALUES (&#8216;$lastupdated&#8217;,'$server&#8217;</p>
<p>,&#8217;$instance&#8217;</p>
<p>,&#8217;$version&#8217;</p>
<p>,&#8217;$Edition&#8217;</p>
<p>,&#8217;$ServicePack&#8217;</p>
<p>,&#8217;$BackupDirectory</p>
<p>,&#8217;$defaultfile&#8217;</p>
<p>,&#8217;$defaultlog&#8217;</p>
<p>,&#8217;$installdatadirectory&#8217;</p>
<p>,&#8217;$osversion&#8217;</p>
<p>,&#8217;$physicalmemory&#8217;</p>
<p>,&#8217;$errorlogpath&#8217;))</p>
<p>AS src</p>
<p>([LastUpdated]</p>
<p>,[Server]</p>
<p>,[Instance]</p>
<p>,[Version]</p>
<p>,[Edition]</p>
<p>,[ServicePack]</p>
<p>,[BackupDirectory]</p>
<p>,[defaultfile]</p>
<p>,[defaultlog]</p>
<p>,[installdatadirectory]</p>
<p>,[osversion]</p>
<p>,[physicalmemory]</p>
<p>,[errorlogpath])</p>
<p>ON (Target.SERVER = (&#8216;$servername&#8217;))</p>
<p>WHEN MATCHED THEN</p>
<p>UPDATE SET lastupdated = (&#8216;$lastupdated&#8217;)</p>
<p>,instance = (&#8216;$instance&#8217;)</p>
<p>,Version = (&#8216;$version&#8217;)</p>
<p>,Edition = (&#8216;$Edition&#8217;)</p>
<p>,Servicepack = (&#8216;$ServicePack&#8217;)</p>
<p>,BackupDirectory = (&#8216;$BackupDirectory&#8217;)</p>
<p>,defaultfile = (&#8216;$DefaultFile&#8217;)</p>
<p>,defaultlog = (&#8216;$DefaultLog&#8217;)</p>
<p>,installdatadirectory = (&#8216;$InstallDataDirectory&#8217;)</p>
<p>,osversion = (&#8216;$OSVersion&#8217;)</p>
<p>,physicalmemory = (&#8216;$PhysicalMemory&#8217;)</p>
<p>,errorlogpath = (&#8216;$ErrorLogPath&#8217;)</p>
<p>WHEN NOT MATCHED THEN</p>
<p>INSERT</p>
<p>([LastUpdated]</p>
<p>,[Server]</p>
<p>,[Instance]</p>
<p>,[Version]</p>
<p>,[Edition]</p>
<p>,[ServicePack]</p>
<p>,[BackupDirectory]</p>
<p>,[defaultfile]</p>
<p>,[defaultlog]</p>
<p>,[installdatadirectory]</p>
<p>,[osversion]</p>
<p>,[physicalmemory]</p>
<p>,[errorlogpath])</p>
<p>VALUES  (&#8216;$lastupdated&#8217;</p>
<p>,&#8217;$server&#8217;</p>
<p>,&#8217;$instance&#8217;</p>
<p>,&#8217;$version&#8217;</p>
<p>,&#8217;$Edition&#8217;</p>
<p>,&#8217;$ServicePack&#8217;</p>
<p>,&#8217;$BackupDirectory&#8217;</p>
<p>,&#8217;$defaultfile&#8217;</p>
<p>,&#8217;$defaultlog&#8217;</p>
<p>,&#8217;$installdatadirectory&#8217;</p>
<p>,&#8217;$osversion&#8217;</p>
<p>,&#8217;$physicalmemory&#8217;</p>
<p>,&#8217;$errorlogpath&#8217;);&#8221;</p>
<p>$cmd.ExecuteNonQuery()</p>
<p>#}</p>
<p>$conn.Close()</p>
<p>#Set the Server as processed</p>
<p>$ServerList.Remove(&#8220;$server&#8221;)</p>
<p>}</p>
<p>I imagine there is an easier way of doing this but it was fun figuring it out. One thing i wanted to get was the start time of the server. I usually use crdate of tempdb in master but i couldn&#8217;t work this into the script. That will be my next step.</p>
<p>Below is the table that the script inserts into</p>
<p><code style="font-size: 12px;"><span style="color: black;"><br />
</span><span style="color: green;">/****** Object:  Table [dbo].[ServerInfo]    Script Date: 05/29/2009 15:46:21 ******/<br />
</span><span style="color: blue;">SET </span><span style="color: black;">ANSI_NULLS </span><span style="color: blue;">ON<br />
</span><span style="color: black;">GO<br />
</span><span style="color: blue;">SET </span><span style="color: black;">QUOTED_IDENTIFIER </span><span style="color: blue;">ON<br />
</span><span style="color: black;">GO<br />
</span><span style="color: blue;">SET </span><span style="color: black;">ANSI_PADDING </span><span style="color: blue;">ON<br />
</span><span style="color: black;">GO<br />
</span><span style="color: blue;">CREATE TABLE </span><span style="color: black;">[dbo].[ServerInfo]</span><span style="color: gray;">(<br />
</span><span style="color: black;">[ServerID] [int] </span><span style="color: #434343;">IDENTITY</span><span style="color: gray;">(</span><span style="color: black;">1</span><span style="color: gray;">,</span><span style="color: black;">1</span><span style="color: gray;">) NOT NULL,<br />
</span><span style="color: black;">[LastUpdated] [datetime] </span><span style="color: gray;">NULL,<br />
</span><span style="color: black;">[Server] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[Instance] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[Version] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[Edition] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[ServicePack] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[TimeStarted] [datetime] </span><span style="color: gray;">NULL,<br />
</span><span style="color: black;">[BackupDirectory] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[defaultfile] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[defaultlog] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[installdatadirectory] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[osversion] [varchar]</span><span style="color: gray;">(</span><span style="color: black;">50</span><span style="color: gray;">) NULL,<br />
</span><span style="color: black;">[physicalmemory] [int] </span><span style="color: gray;">NULL,<br />
</span><span style="color: black;">[errorlogpath] [nvarchar]</span><span style="color: gray;">(</span><span style="color: black;">250</span><span style="color: gray;">) NULL,<br />
</span><span style="color: blue;">CONSTRAINT </span><span style="color: black;">[PK_ServerInfo] </span><span style="color: blue;">PRIMARY KEY CLUSTERED<br />
</span><span style="color: gray;">(<br />
</span><span style="color: black;">[ServerID] </span><span style="color: blue;">ASC<br />
</span><span style="color: gray;">)</span><span style="color: blue;">WITH </span><span style="color: gray;">(</span><span style="color: black;">PAD_INDEX </span><span style="color: blue;">= OFF</span><span style="color: gray;">, </span><span style="color: black;">STATISTICS_NORECOMPUTE </span><span style="color: blue;">= OFF</span><span style="color: gray;">,</p>
<p></span><span style="color: black;">IGNORE_DUP_KEY </span><span style="color: blue;">= OFF</span><span style="color: gray;">, </span><span style="color: black;">ALLOW_ROW_LOCKS </span><span style="color: blue;">= ON</span><span style="color: gray;">, </span><span style="color: black;">ALLOW_PAGE_LOCKS </span><span style="color: blue;">= ON</span><span style="color: gray;">) </span><span style="color: blue;">ON </span><span style="color: black;">[PRIMARY]<br />
</span><span style="color: gray;">) </span><span style="color: blue;">ON </span><span style="color: black;">[PRIMARY]<br />
GO<br />
</span><span style="color: blue;">SET </span><span style="color: black;">ANSI_PADDING </span><span style="color: blue;">OFF<br />
</span><span style="color: black;">GO</p>
<p></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://underthefold.org/2009/12/19/powershell-monitoring-and-the-central-management-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
