<?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>Henderson Consulting &#187; Mike</title>
	<atom:link href="http://www.mohenderson.com/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mohenderson.com</link>
	<description>Thoughts on data &#38; programming by Michael Henderson</description>
	<lastBuildDate>Fri, 13 Jan 2012 03:05:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>String manipulations with the SSIS Script Component</title>
		<link>http://www.mohenderson.com/2012/01/12/string-manipulations-with-the-ssis-script-component/</link>
		<comments>http://www.mohenderson.com/2012/01/12/string-manipulations-with-the-ssis-script-component/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 02:55:26 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Data Integration]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=327</guid>
		<description><![CDATA[Problem: Your source data contains a column that should be split in two. In this case there is a name column in an Excel file that contains both the first and last name. The destination database has the first and &#8230; <a href="http://www.mohenderson.com/2012/01/12/string-manipulations-with-the-ssis-script-component/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> Your source data contains a column that should be split in two. In this case there is a name column in an Excel file that contains both the first and last name. The destination database has the first and last name as separate columns.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/strings_and_script_component/excelsample.png" alt="Excel Sample" width="204" height="218" /><strong> </strong></p>
<p><strong>Solution:</strong> Use the script the component and split apart the column data into a string array.</p>
<p><strong>Step I:</strong> In a Data Flow add an Excel source and then add a Script Component with the component type “Transformation.” Add a First Name, Middle Name and Last Name as column outputs. Be sure to add the name column from the source data as an input column.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/strings_and_script_component/addscriptcomponent.png" alt="Add Script Component" width="436" height="389" /><strong> </strong></p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/strings_and_script_component/dataflowview.png" alt="Data Flow View" width="363" height="306" /></p>
<p><strong><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/strings_and_script_component/outputcolumns.png" alt="Output Columns" width="349" height="239" /></strong></p>
<p><strong>Step II:</strong> Open the script editing window and edit the ProcessInputRow method. In this example were going to assume that each name is separated by a space. Using the String.Split() method, break up the name column into a string array. If the array length is 3, then we have a first, last and middle name. If the array length is only 2, then only the first and last name is present.<strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Step III:</strong> Assign the output columns with the appropriate item from the index.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw4">class</span> ScriptMain <span class="sy0">:</span> UserComponent<br />
<span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">override</span> <span class="kw1">void</span> InputCustomers_ProcessInputRow<span class="br0">&#40;</span>InputCustomersBuffer Row<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var names <span class="sy0">=</span> Row.<span class="me1">Name</span>.<span class="me1">Split</span><span class="br0">&#40;</span><span class="st0">&#8216; &#8216;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//if lenght is two, not middle skip the middle name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>names.<span class="me1">Length</span> <span class="sy0">==</span> 2<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Row.<span class="me1">FirstName</span> <span class="sy0">=</span> names<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Row.<span class="me1">LastName</span> <span class="sy0">=</span> names<span class="br0">&#91;</span>1<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>names.<span class="me1">Length</span> <span class="sy0">==</span> 3<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Row.<span class="me1">FirstName</span> <span class="sy0">=</span> names<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Row.<span class="me1">MiddleName</span> <span class="sy0">=</span> names<span class="br0">&#91;</span>1<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Row.<span class="me1">LastName</span> <span class="sy0">=</span> names<span class="br0">&#91;</span>2<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>We now have three columns ready to be passed to the destination data source.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/strings_and_script_component/dataview.png" alt="Data view" width="611" height="174" /></p>
<div id="_mcePaste" class="mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">String manipulations with the SSIS Script Component</div>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2012/01/12/string-manipulations-with-the-ssis-script-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML and Me</title>
		<link>http://www.mohenderson.com/2012/01/06/xml-and-me/</link>
		<comments>http://www.mohenderson.com/2012/01/06/xml-and-me/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 12:29:15 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=321</guid>
		<description><![CDATA[Starting with the Spring Semester at Northwestern Michigan College, I will be teaching an introductory course in XML (CIT 185 &#8211; XML Programming). Teaching in some capacity has been an item in my &#8220;bucket list&#8221; for some time. So I &#8230; <a href="http://www.mohenderson.com/2012/01/06/xml-and-me/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Starting with the Spring Semester at <a href="https://www.nmc.edu/">Northwestern Michigan College</a>, I will be teaching an introductory course in XML (CIT 185 &#8211; XML Programming).</p>
<p>Teaching in some capacity has been an item in my &#8220;bucket list&#8221; for some time. So I am excited to begin sharing the love with XML, XSLT, XQuery and friends. And teaching at NMC has special significance. Fourteen years ago when I was just starting out in the IT world I took a database course at NMC. Now I hope to help someone else get started as a programmer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2012/01/06/xml-and-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSAS Database Backup Utility with AMO</title>
		<link>http://www.mohenderson.com/2011/12/10/ssas-database-backup-utility-with-amo/</link>
		<comments>http://www.mohenderson.com/2011/12/10/ssas-database-backup-utility-with-amo/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 03:36:31 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[AMO]]></category>
		<category><![CDATA[SSAS]]></category>
		<category><![CDATA[Functional Programming]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=303</guid>
		<description><![CDATA[There are few, and I do mean a few, examples of backing up your SSAS databases in an automated fashion. For a couple of years I have used a method of looping through a list in SSIS and executing an &#8230; <a href="http://www.mohenderson.com/2011/12/10/ssas-database-backup-utility-with-amo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are few, and I do mean a few, examples of backing up your SSAS databases in an automated fashion. For a couple of years I have used a method of looping through a list in SSIS and executing an XMLA script. In this post I will demonstrate create a console application using <a title="Link to MSDN site" href="http://msdn.microsoft.com/en-us/library/ms146720.aspx" target="_blank">Analysis Management Objects (AMO)</a>.</p>
<p><strong>Step 1:  Create a console application</strong></p>
<p>Create a console application in Visual Studio and add Microsoft.AnalysisServices to your references.</p>
<p><strong>Step 2: Add a new class Argument Parser class.</strong></p>
<p>The code in this class is used almost verbatim from a handy post at <a title=".Net scraps site." href="http://goo.gl/OCP5p" target="_blank">.Net Scraps</a>.</p>
<p><strong>Step 3: Add a new class Processing.</strong></p>
<p>This class will have all the code doing the backup. The method BackupSsasDatabases connects to the server identified in arguments passed in. Once connected to the server, we then loop through the SSAS databases enumerated in the DatabaseCollection. There is a helper method called GetBackupInfo that returns an instance of the BackupInfoClass and is used as an argument for the Backup method.</p>
<p>The GetFilePath method uses an argument passed into the application indicating the destination for the backup file, and builds the file name from the database name and the date and time of the backup.</p>
<p><strong>Step 4: Arguments</strong></p>
<p>There are four arguments the application uses. The first two are required and the second two are optional:</p>
<ol>
<li>ServerName : The name of the server you’re connecting to</li>
<li>Path: The destination directory for the backup file</li>
<li>AllowOverwrite: Used in BackupInfo class</li>
<li>BackupRemotePartitions: Used in BackupInfo class</li>
</ol>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw4">class</span> Program<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">static</span> <span class="kw1">void</span> Main<span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>args.<span class="me1">Length</span> <span class="sy0">&gt;</span> 0<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hashtable _args <span class="sy0">=</span> ArgumentParser.<span class="me1">Parse</span><span class="br0">&#40;</span>args<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//if we don&#8217;t have the required arguments, call it quits</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//if we do have the required arguments, proceed.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_args.<span class="me1">ContainsKey</span><span class="br0">&#40;</span><span class="st0">&quot;ServerName&quot;</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> _args.<span class="me1">ContainsKey</span><span class="br0">&#40;</span><span class="st0">&quot;Path&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var proc <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Processing<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc.<span class="me1">BackupSsasDatabases</span><span class="br0">&#40;</span>_args<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//write out info on missing arguments</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>_args.<span class="me1">ContainsKey</span><span class="br0">&#40;</span><span class="st0">&quot;ServerName&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;ServerName argument is missing&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>_args.<span class="me1">ContainsKey</span><span class="br0">&#40;</span><span class="st0">&quot;Path&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Path argument is missing&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Press any key to continue&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">ReadKey</span><span class="br0">&#40;</span><span class="kw1">true</span><span class="br0">&#41;</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;No arguments passed&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Press any key to continue&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">ReadKey</span><span class="br0">&#40;</span><span class="kw1">true</span><span class="br0">&#41;</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="co1">// class</span></div>
</div>
<p><br/><br/></p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw4">class</span> Processing<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">#region Backup SSAS Databases.</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// Backup SSAS Databases.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;param name=&quot;_serverName&quot;&gt;&lt;/param&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">void</span> BackupSsasDatabases<span class="br0">&#40;</span>Hashtable args<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var _serverName <span class="sy0">=</span> args<span class="br0">&#91;</span><span class="st0">&quot;ServerName&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">using</span><span class="br0">&#40;</span>Server srv <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Server<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; srv.<span class="me1">Connect</span><span class="br0">&#40;</span>_serverName<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span>Database db <span class="kw1">in</span> srv.<span class="me1">Databases</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Backing up &quot;</span> <span class="sy0">+</span> db.<span class="me1">Name</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Start &quot;</span> <span class="sy0">+</span> DateTime.<span class="me1">Now</span>.<span class="me1">ToShortTimeString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var backupInfo <span class="sy0">=</span> GetBackupInfo<span class="br0">&#40;</span>db.<span class="me1">Name</span>, args<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db.<span class="me1">Backup</span><span class="br0">&#40;</span>backupInfo<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Done &quot;</span> <span class="sy0">+</span> DateTime.<span class="me1">Now</span>.<span class="me1">ToShortTimeString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; srv.<span class="me1">Disconnect</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">#endregion</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">#region Get File Path</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// build file path for backup.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;param name=&quot;name&quot;&gt;&lt;/param&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;returns&gt;&lt;/returns&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">string</span> GetFilePath<span class="br0">&#40;</span><span class="kw4">string</span> name, <span class="kw4">string</span> path<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var c <span class="sy0">=</span> DateTime.<span class="me1">Now</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var f <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span>path<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span>name.<span class="me1">Replace</span><span class="br0">&#40;</span><span class="st0">&quot; &quot;</span>,<span class="st0">&quot;_&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span><span class="st0">&quot;_&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span>c.<span class="me1">Year</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span>c.<span class="me1">Month</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span>c.<span class="me1">Day</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span><span class="st0">&quot;_&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span>c.<span class="me1">Hour</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="st0">&quot;D&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span>c.<span class="me1">Minute</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="st0">&quot;D&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span class="me1">Append</span><span class="br0">&#40;</span><span class="st0">&quot;.abf&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> f.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">#endregion</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">#region Get Backup Info</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// Get Backup Info</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;param name=&quot;name&quot;&gt;&lt;/param&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// &lt;returns&gt;&lt;/returns&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; BackupInfo GetBackupInfo<span class="br0">&#40;</span><span class="kw4">string</span> name, Hashtable args<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var backupInfo <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> BackupInfo<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; backupInfo.<span class="me1">AllowOverwrite</span> <span class="sy0">=</span> args.<span class="me1">ContainsKey</span><span class="br0">&#40;</span><span class="st0">&quot;AllowOverwrite&quot;</span><span class="br0">&#41;</span><span class="sy0">?</span> Convert.<span class="me1">ToBoolean</span><span class="br0">&#40;</span>args<span class="br0">&#91;</span><span class="st0">&quot;AllowOverwrite&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">:</span> true<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; backupInfo.<span class="me1">BackupRemotePartitions</span> <span class="sy0">=</span> args.<span class="me1">ContainsKey</span><span class="br0">&#40;</span><span class="st0">&quot;BackupRemotePartitions&quot;</span><span class="br0">&#41;</span> <span class="sy0">?</span> Convert.<span class="me1">ToBoolean</span><span class="br0">&#40;</span>args<span class="br0">&#91;</span><span class="st0">&quot;BackupRemotePartitions&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">:</span> false<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; backupInfo.<span class="me1">File</span> <span class="sy0">=</span> GetFilePath<span class="br0">&#40;</span>name, args<span class="br0">&#91;</span><span class="st0">&quot;Path&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> backupInfo<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">#endregion</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="co1">// class</span></div>
</div>
<p><strong>Step 4: Create a batch file and backup your SSAS databases.</strong></p>
<p><strong>Summary</strong></p>
<p>There are other approaches to backing up your SSAS databases (Powershell comes to mind). This is one is offered as a backup processing solution tied together in an .exe file.</p>
<a class="downloadlink" href="http://www.mohenderson.com/wp-content/plugins/download-monitor/download.php?id=1" title="Version1 downloaded 33 times" >Download Backup SSAS Database Code (33)</a>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/12/10/ssas-database-backup-utility-with-amo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Knee Deep in Azure Table Storage</title>
		<link>http://www.mohenderson.com/2011/12/05/knee-deep-in-azure-table-storage/</link>
		<comments>http://www.mohenderson.com/2011/12/05/knee-deep-in-azure-table-storage/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 02:29:29 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Data Integration]]></category>
		<category><![CDATA[Personal Musings]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[Azure Table Storage]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=299</guid>
		<description><![CDATA[I have been trying to work up a demo using SSIS and Azure Table Storage. I keep getting distracted with other minutia of Azure that is interesting, but I have not been able to contain it in a blog post. &#8230; <a href="http://www.mohenderson.com/2011/12/05/knee-deep-in-azure-table-storage/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been trying to work up a demo using SSIS and Azure Table Storage. I keep getting distracted with other minutia of Azure that is interesting, but I have not been able to contain it in a blog post.</p>
<p>Just the same, Azure table storage is quite an interesting animal. Not a relational store like SQL Azure. Not really a NoSQL alternative like Mongo DB (read steep learning curve). I am hoping to have something more substantive to share soon because once the get it down, I can see a whole new world of data storage and revival opening up.</p>
<p>Another upcoming topic: fun with HTML5/ASP MVC/Razor.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/12/05/knee-deep-in-azure-table-storage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with MongoDB and SSIS</title>
		<link>http://www.mohenderson.com/2011/11/14/working-with-mongodb-and-ssis/</link>
		<comments>http://www.mohenderson.com/2011/11/14/working-with-mongodb-and-ssis/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 09:54:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=279</guid>
		<description><![CDATA[A little over a year ago I saw a presentation on NoSQL (i.e. Not Only SQL), and specifically MongoDB. MongoDB is an open source document oriented database, and like many things related to NoSQL it seems to have a buzz &#8230; <a href="http://www.mohenderson.com/2011/11/14/working-with-mongodb-and-ssis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A little over a year ago I saw a presentation on NoSQL (i.e. Not Only SQL), and specifically MongoDB. MongoDB is an open source document oriented database, and like many things related to NoSQL it seems to have a buzz about it. In this blog post I will demonstrate using SSIS and MongoDB.</p>
<p><strong>The Basics</strong></p>
<p>I am not going to detail installing MongoDB and related drivers, the MongoDB already does fair job and I recommend following their documentation. For the purposes of this demonstration I installed <a href="http://www.mongodb.org/">MongoDB</a> and the <a href="http://www.mongodb.org/display/DOCS/CSharp+Language+Center">C# drivers</a>.</p>
<p>Once the MongoDB prerequisites have been installed, create an SSIS package and add a Data Flow. In the data flow I added a flat file source that will extract a list of countries from a CSV file. Then add a Script Component and select “Destination” as the Script Component Type.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssos_mongo/dataflow.png" alt="Data Flow" width="292" height="203" /></p>
<p>Next open the script editor and add the following references and usings:</p>
<ol>
<li>MongoDB.Bson</li>
<li>MongoDB.Driver</li>
</ol>
<p><strong>The Code</strong></p>
<p>I created a Country class as part of my ETL, but this is not necessary and I would refer one to the C# driver tutorial for other approaches. In a pretty concise manner, I was able to connection the server, database and add the country data.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">using</span> <span class="co3">System</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">System.Data</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">Microsoft.SqlServer.Dts.Pipeline.Wrapper</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">Microsoft.SqlServer.Dts.Runtime.Wrapper</span><span class="sy0">;</span></p>
<p><span class="kw1">using</span> <span class="co3">MongoDB.Bson</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">MongoDB.Driver</span><span class="sy0">;</span></p>
<p><span class="br0">&#91;</span>Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Pipeline</span>.<span class="me1">SSISScriptComponentEntryPointAttribute</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> ScriptMain <span class="sy0">:</span> UserComponent<br />
<span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">override</span> <span class="kw1">void</span> InputCountry_ProcessInputRow<span class="br0">&#40;</span>InputCountryBuffer Row<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var connectionString <span class="sy0">=</span> <span class="st0">&quot;mongodb://localhost&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var mongo <span class="sy0">=</span> MongoServer.<span class="me1">Create</span><span class="br0">&#40;</span>connectionString<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; var db <span class="sy0">=</span> mongo.<span class="me1">GetDatabase</span><span class="br0">&#40;</span><span class="st0">&quot;MyMongoDb&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; MongoCollection<span class="sy0">&lt;</span>Country<span class="sy0">&gt;</span> countries <span class="sy0">=</span> db.<span class="me1">GetCollection</span><span class="sy0">&lt;</span>Country<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="st0">&quot;Countries&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; var country <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Country <span class="br0">&#123;</span> CountryCode <span class="sy0">=</span> Row.<span class="me1">CountryCode</span>, CountryName <span class="sy0">=</span> Row.<span class="me1">CountryName</span> <span class="br0">&#125;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; countries.<span class="me1">Insert</span><span class="br0">&#40;</span>country<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>
<span class="br0">&#125;</span></p>
<p><span class="kw1">public</span> <span class="kw4">class</span> Country<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">string</span> CountryCode <span class="br0">&#123;</span> get<span class="sy0">;</span> set<span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">string</span> CountryName <span class="br0">&#123;</span> get<span class="sy0">;</span> set<span class="sy0">;</span> <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>In this demonstration I showed how to use SSIS and create an ETL with MongoDB. This turned out pretty easy as I was able to download, install, and create this proof of concept on a Sunday. Not to mention juggling other weekend chores.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/11/14/working-with-mongodb-and-ssis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Windows Azure Marketplace Data with SSIS</title>
		<link>http://www.mohenderson.com/2011/11/05/using-windows-azure-marketplace-data-with-ssis/</link>
		<comments>http://www.mohenderson.com/2011/11/05/using-windows-azure-marketplace-data-with-ssis/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 18:49:52 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[Data Integration]]></category>
		<category><![CDATA[Service Oriented Architecture]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[OData]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=236</guid>
		<description><![CDATA[In this blog post I will describe using Microsoft Windows Azure Marketplace Data and SSIS. The Azure Marketplace allows one to buy and sell Software-as-a-Service applications and datasets. Most of the services are available for a subscription fee, but there &#8230; <a href="http://www.mohenderson.com/2011/11/05/using-windows-azure-marketplace-data-with-ssis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this blog post I will describe using <a title="Windows Azure Marketplace" href="https://datamarket.azure.com/" target="_blank">Microsoft Windows Azure Marketplace Data</a> and SSIS. The Azure Marketplace allows one to buy and sell Software-as-a-Service applications and datasets. Most of the services are available for a subscription fee, but there are also several offered for free.</p>
<p>For the purposes of this demonstration I will use data from the <a title="Practice Fusion Data" href="http://www.practicefusion.com/pages/emr-research-center.html" target="_blank">Practice Fusion Medical Research Data</a>, which is available for free. This data is available for research purposes and contains HIPPA compliant de-identified data. I have a personal interest in Autism and want to direct some after-work energy seeking out and analyzing Autism data. Unfortunately what I extracted from the sample dataset thus far does not have any Autism related data. Just the same it has been a good exercise in doing ETL with data services.</p>
<p><strong>Add variables</strong></p>
<p><strong><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/azure_marketplace_data_with_ssis/variables.png" alt="Variables" width="643" height="156" /><br />
</strong></p>
<p>Add three variables to your package. One is for the account key and one for the User ID, which can found in the My Account section. The third variable is the service root. This can be found in the details section of the service one is subscribing to.</p>
<p><strong>Add Data Flow &amp; Script Component</strong></p>
<p>Add a Data Flow to a package. Inside the Data Flow, add a Script Component and select Script Component Type of Source.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/azure_marketplace_data_with_ssis/addscriptcomponent.png" alt="Add Script Component" width="453" height="210" /></p>
<p>Add the appropriate columns you want to extract from the service.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/azure_marketplace_data_with_ssis/addcolumns.png" alt="Add Columns" width="441" height="155" /></p>
<p>Add a service reference and use the Service Root URL.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/azure_marketplace_data_with_ssis/addservicereference.png" alt="Add service reference." width="632" height="509" /></p>
<p><strong>Consume the Data with Managed Code.</strong></p>
<p>At this point the data can be queried with a Linq expression and output rows generated. For more information see the MSDN documentation on creating application with Azure Marketplace Data.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">using</span> <span class="co3">System</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">System.Collections</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">System.Data</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">System.Linq</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">System.Net</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">Microsoft.SqlServer.Dts.Pipeline.Wrapper</span><span class="sy0">;</span><br />
<span class="kw1">using</span> <span class="co3">Microsoft.SqlServer.Dts.Runtime.Wrapper</span><span class="sy0">;</span></p>
<p><span class="kw1">using</span> <span class="co3">SC_c0e4421be5a54826af3fe68d3227f2be.PracticeFusion</span><span class="sy0">;</span></p>
<p>
<span class="br0">&#91;</span>Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Pipeline</span>.<span class="me1">SSISScriptComponentEntryPointAttribute</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> ScriptMain <span class="sy0">:</span> UserComponent<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">override</span> <span class="kw1">void</span> CreateNewOutputRows<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var serviceUri <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Uri<span class="br0">&#40;</span>Variables.<span class="me1">ServiceRootUrl</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var context <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> PracticeFusionMedicalResearchDataContainer<span class="br0">&#40;</span>serviceUri<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; context.<span class="me1">Credentials</span> <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> NetworkCredential<span class="br0">&#40;</span>Variables.<span class="me1">UserID</span>, Variables.<span class="me1">Key</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var diagnosis <span class="sy0">=</span> context.<span class="me1">SyncDiagnosis</span>.<span class="me1">ToList</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span>SyncDiagnosis d <span class="kw1">in</span> diagnosis<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">AddRow</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">DiagnosisGuid</span> <span class="sy0">=</span> d.<span class="me1">DiagnosisGuid</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">PatientGuid</span> <span class="sy0">=</span> d.<span class="me1">PatientGuid</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">ICD9Code</span> <span class="sy0">=</span> d.<span class="me1">ICD9Code</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">DiagnosisDescription</span> <span class="sy0">=</span> d.<span class="me1">DiagnosisDescription</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">StartYear</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span><span class="br0">&#40;</span>d.<span class="me1">StartYear</span> <span class="sy0">&gt;</span> 0 <span class="sy0">?</span> d.<span class="me1">StartYear</span> <span class="sy0">:</span> 0<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">StopYear</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span><span class="br0">&#40;</span>d.<span class="me1">StopYear</span> <span class="sy0">&gt;</span> 0 <span class="sy0">?</span> d.<span class="me1">StopYear</span> <span class="sy0">:</span> 0<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputDiagnosisBuffer.<span class="me1">Acute</span> <span class="sy0">=</span> d.<span class="me1">Acute</span> <span class="sy0">==</span> <span class="kw1">true</span> <span class="sy0">?</span> <span class="kw1">true</span> <span class="sy0">:</span> false<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>In this blog post I demonstrated how to consume data made available using the Window Azure Marketplace. I see this as useful where one would like to extract external data for the Business intelligence needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/11/05/using-windows-azure-marketplace-data-with-ssis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating Rows for Date Dimension</title>
		<link>http://www.mohenderson.com/2011/10/22/generating-rows-for-date-dimension/</link>
		<comments>http://www.mohenderson.com/2011/10/22/generating-rows-for-date-dimension/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 23:00:12 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Data Integration]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=225</guid>
		<description><![CDATA[I was recently looking up scripts for populating date dimension tables. The scripts I reviewed were cribbed or otherwise stolen from other how-to documents. They all followed a sequence of establishing a start and end date range, and populating rows &#8230; <a href="http://www.mohenderson.com/2011/10/22/generating-rows-for-date-dimension/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was recently looking up scripts for populating date dimension tables. The scripts I reviewed were cribbed or otherwise stolen from other how-to documents. They all followed a sequence of establishing a start and end date range, and populating rows via a <em>while</em> loop. Generally speaking, I try to avoid while loops in SQL as it smacks of RBAR, or Row by Agonizing Row.</p>
<p>I started wondering if there was a better way, and then remembered a trick I saw demonstrated in a webinar.  The demo showed how to efficiently populate tables with large amounts of test data. The trick is to query system tables to artificially return large lots of rows.</p>
<p><img class="ngg-singlepic ngg-none" src="http://www.mohenderson.com/wp-content/gallery/20111022/calendartable.png" alt="Calendar Table" /></p>
<p>To start I want to return enough rows to cover the date range to be inserted in the table illustrated above. This is done by selecting from the system table sys.all_objects. To get the number of rows I need, I return the Top n number of rows selected. The exact number is determined by doing a DATEDIFF using the minimum and maximum dates.</p>
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;">DECLARE @date date <span class="sy0">=</span> <span class="st0">&#8217;12/31/1999&#8242;</span>;<br />
DECLARE @stop date <span class="sy0">=</span> <span class="st0">&#8217;12/31/2020&#8242;</span>;</p>
<p><span class="kw1">SELECT</span> &nbsp;TOP <span class="br0">&#40;</span>DATEDIFF<span class="br0">&#40;</span>DAY<span class="sy0">,</span>@date<span class="sy0">,</span>@stop<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
@date</p>
<p><span class="kw1">FROM</span> sys<span class="sy0">.</span>all_objects <span class="kw1">AS</span> O</div>
</div>
<p>Now add an incrementing number using the ROW_NUMBER() function. Combined with the DATEADD function I now have all the dates I need for my dimension table.</p>
<p><img style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/20111022/rownumbers.png" alt="Row Numbers" width="540" height="258" /></p>
<p>At this point start filling out the other columns with the appropriate date related functions.</p>
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;">DECLARE @date date <span class="sy0">=</span> <span class="st0">&#8217;12/31/2009&#8242;</span>;<br />
DECLARE @stop date <span class="sy0">=</span> <span class="st0">&#8217;12/31/2010&#8242;</span>;</p>
<p><span class="kw1">SELECT</span> &nbsp;TOP <span class="br0">&#40;</span>DATEDIFF<span class="br0">&#40;</span>DAY<span class="sy0">,</span>@date<span class="sy0">,</span>@stop<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
DATEADD<span class="br0">&#40;</span>DAY<span class="sy0">,</span>ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> OVER <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> O<span class="sy0">.</span>object_id<span class="br0">&#41;</span><span class="sy0">,</span> @date<span class="br0">&#41;</span> <span class="kw1">AS</span> CalendarDate<br />
<span class="sy0">,</span> DATEPART<span class="br0">&#40;</span>DW<span class="sy0">,</span>DATEADD<span class="br0">&#40;</span>DAY<span class="sy0">,</span>ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> OVER <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> O<span class="sy0">.</span>object_id<span class="br0">&#41;</span><span class="sy0">,</span> @date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> DayNumberOfWeek<br />
<span class="sy0">,</span> DATENAME<span class="br0">&#40;</span>WEEKDAY<span class="sy0">,</span>DATEADD<span class="br0">&#40;</span>DAY<span class="sy0">,</span>ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> OVER <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> O<span class="sy0">.</span>object_id<span class="br0">&#41;</span><span class="sy0">,</span> @date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> DayNameOfWeek<br />
<span class="sy0">,</span> DATEPART<span class="br0">&#40;</span>MONTH<span class="sy0">,</span>DATEADD<span class="br0">&#40;</span>DAY<span class="sy0">,</span>ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> OVER <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> O<span class="sy0">.</span>object_id<span class="br0">&#41;</span><span class="sy0">,</span> @date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> MonthNumber<br />
<span class="sy0">,</span> DATENAME<span class="br0">&#40;</span>MONTH<span class="sy0">,</span>DATEADD<span class="br0">&#40;</span>DAY<span class="sy0">,</span>ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> OVER <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> O<span class="sy0">.</span>object_id<span class="br0">&#41;</span><span class="sy0">,</span> @date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> <span class="br0">&#91;</span>MonthName<span class="br0">&#93;</span><br />
<span class="sy0">,</span> DATEPART<span class="br0">&#40;</span>QUARTER<span class="sy0">,</span>DATEADD<span class="br0">&#40;</span>DAY<span class="sy0">,</span>ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> OVER <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> O<span class="sy0">.</span>object_id<span class="br0">&#41;</span><span class="sy0">,</span> @date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> CalendarQuarter<br />
<span class="sy0">,</span> DATEPART<span class="br0">&#40;</span>YEAR<span class="sy0">,</span>DATEADD<span class="br0">&#40;</span>DAY<span class="sy0">,</span>ROW_NUMBER<span class="br0">&#40;</span><span class="br0">&#41;</span> OVER <span class="br0">&#40;</span><span class="kw1">ORDER</span> <span class="kw1">BY</span> O<span class="sy0">.</span>object_id<span class="br0">&#41;</span><span class="sy0">,</span> @date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> CalendarYear</p>
<p><span class="kw1">FROM</span> &nbsp; &nbsp;sys<span class="sy0">.</span>all_objects <span class="kw1">AS</span> O</div>
</div>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/20111022/calendarrows.png" alt="Calendar Rows" width="680" height="207" /></p>
<p>And there, dynamically generated rows for a date dimension and now <em>while</em> loop in sight.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/10/22/generating-rows-for-date-dimension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS: Dynamically Configuring the Data Connection Manager</title>
		<link>http://www.mohenderson.com/2011/10/20/ssis-dynamically-configuring-the-data-connection-manager/</link>
		<comments>http://www.mohenderson.com/2011/10/20/ssis-dynamically-configuring-the-data-connection-manager/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 01:34:20 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[Data Integration]]></category>
		<category><![CDATA[Database BI]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=212</guid>
		<description><![CDATA[In the last post I described using the WMI Data Reader Task. The data collected is by nature dynamic. Servers are stood up and decommissioned, as are databases. In this post I’ll demonstrate retrieving data from a changing list of &#8230; <a href="http://www.mohenderson.com/2011/10/20/ssis-dynamically-configuring-the-data-connection-manager/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the last post I described using the <em>WMI Data Reader Task</em>. The data collected is by nature dynamic. Servers are stood up and decommissioned, as are databases. In this post I’ll demonstrate retrieving data from a changing list of servers.</p>
<p><strong>Create Variables</strong></p>
<p>To start, create a variable with a type of Object. Make sure the scope is package wide. The object is going to be created in one <em>Data Flow</em> and then used later in a <em>For Each Loop </em>container. Variables are by default created in the current scope. This caused me several headaches when I first started doing SSIS. A nice change in SQL Denali is the scope of variables will be package in scope by default.</p>
<p>Next create a variable of type string to hold the name of the server. Again, be sure the variable scope is package wide.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_dynamicdataconnection/servernamevariable.png" alt="Server Variables" width="479" height="110" /></p>
<p><strong>Populate the Server List Variable</strong></p>
<p>Create a <em>Data Flow</em> and add a <em>Data Source</em> that retrieves your list of services. For the destination add a <em>Recordset Destination </em>set the variable to the server list variable.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_dynamicdataconnection/serverlist.png" alt="Server List" width="300" height="133" /></p>
<p><strong>Create Data Connection Manager</strong></p>
<p>Create a WMI Data Connection Manager. In the last post I described using the WMI Data Reader Task. Now I am going to place this task inside a For Each Loop container and loop through a list of servers.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_dynamicdataconnection/connectionmanagersettings.png" alt="Connection Manager Settings" width="565" height="288" /></p>
<p>In the <em>Data Connection Manager</em> properties, click the Properties Expressions Editor. Select the Connection String and Server Name properties. Now add expressions to build the strings for these properties:</p>
<p>Connection String: &#8220;ServerName=\\\\&#8221; + @[User::ServerNameWmi]  + &#8220;;Namespace=\\root\\cimv2;UseNtAuth=True;UserName=;&#8221;</p>
<p>Server Name: &#8220;\\\\&#8221; +  @[User::ServerNameWmi]</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_dynamicdataconnection/propertyconnectionmanager.png" alt="Property Connection Manager" width="448" height="156" /></p>
<p>Now add a <em>For Each Loop Container</em> to a <em>Control Flow</em>. Set the Enumerator property to Foreach ADO Enumerator. Set the ADO Object Source Variable to the object variable created earlier. In the variable mappings set the server name variable.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_dynamicdataconnection/foreachloopcontainer.png" alt="For Each Loop Container" width="425" height="378" /></p>
<p>And now one can gather information on however many servers returned in the initial query.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/10/20/ssis-dynamically-configuring-the-data-connection-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the WMI Reader Task</title>
		<link>http://www.mohenderson.com/2011/10/18/using-the-wmi-reader-task/</link>
		<comments>http://www.mohenderson.com/2011/10/18/using-the-wmi-reader-task/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 02:07:07 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Data Integration]]></category>
		<category><![CDATA[Database BI]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=196</guid>
		<description><![CDATA[This is another post in my Database BI series. In past posts I described using SMO objects to retrieve data about the SQL Server instances and databases. This post will describe using the WMI Reader Task to gather information about &#8230; <a href="http://www.mohenderson.com/2011/10/18/using-the-wmi-reader-task/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is another post in my Database BI series. In past posts I described using SMO objects to retrieve data about the SQL Server instances and databases. This post will describe using the WMI Reader Task to gather information about a server’s disk drive. This will be used to track size and growth of databases relative to the rest of the server, and plan for future growth.</p>
<p>To start, create a WMI Connection Manager. The server name is defaulted to localhost, you may have to edit this to \\&lt;server_name&gt; as needed.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/wmiconnectionmanager.png" alt="WMI Connection Manager Image" width="400" height="326" /></p>
<p>Add a variable with a data type of object. The WMI Reader task will output a DataTable to this object.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/wmiobjectvariable.png" alt="Image of object variable" width="435" height="29" /></p>
<p>Add a WMI Data Reader Task and a Data Flow Task to your control flow.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/wmireader1.png" alt="Control Flow Image" width="288" height="209" /></p>
<p>Configure the WMI Reader.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/wmireader2.png" alt="Configure WMI Reader Image" width="594" height="247" /></p>
<p>Below is the WQL Query. There is much more to be gleaned, but for the purposes of this application, these columns will do.</p>
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">SELECT</span> Caption<span class="sy0">,</span> Description<span class="sy0">,</span> DriveType<span class="sy0">,</span> FileSystem<span class="sy0">,</span> FreeSpace<span class="sy0">,</span> Name<span class="sy0">,</span> Size<span class="sy0">,</span> <span class="kw1">STATUS</span><span class="sy0">,</span> SystemName<span class="sy0">,</span> VolumeName<br />
<span class="kw1">FROM</span> Win32_LogicalDisk</div>
</div>
<p>In the Data Flow task create a script component and select the script component type of source.<br />
<img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/wmireader4.png" alt="Script Transformation Type Image" width="351" height="316" /></p>
<p>Add output columns based on what’s in the WQL Query. Pass in the object variable as a read only variable.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/setscriptcomponentcolumns.png" alt="Set Script Component Columns" width="443" height="261" /></p>
<p>Then in the code, loop through the data table to create output rows.</p>
<div class="codesnip-container" >
<div class="c codesnip" style="font-family:monospace;"><span class="coMULTI">/* Microsoft SQL Server Integration Services Script Component<br />
* &nbsp;Write scripts using Microsoft Visual C# 2010.<br />
* &nbsp;ScriptMain is the entry point class of the script.*/</span></p>
<p>using System<span class="sy0">;</span><br />
using System.<span class="me1">Data</span><span class="sy0">;</span><br />
using Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Pipeline</span>.<span class="me1">Wrapper</span><span class="sy0">;</span><br />
using Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Runtime</span>.<span class="me1">Wrapper</span><span class="sy0">;</span></p>
<p><span class="br0">&#91;</span>Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Pipeline</span>.<span class="me1">SSISScriptComponentEntryPointAttribute</span><span class="br0">&#93;</span><br />
public class ScriptMain <span class="sy0">:</span> UserComponent<br />
<span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; public override <span class="kw4">void</span> CreateNewOutputRows<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var wmi <span class="sy0">=</span> <span class="br0">&#40;</span>DataTable<span class="br0">&#41;</span>Variables.<span class="me1">ServerDataWmi</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; foreach <span class="br0">&#40;</span>DataRow row in wmi.<span class="me1">Rows</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">AddRow</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">Caption</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>0<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">Description</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>1<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">DriveType</span> <span class="sy0">=</span> Convert.<span class="me1">ToInt32</span><span class="br0">&#40;</span>row<span class="br0">&#91;</span>2<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">FileSystem</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>3<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>row<span class="br0">&#91;</span>4<span class="br0">&#93;</span> <span class="sy0">!=</span> System.<span class="me1">DBNull</span>.<span class="me1">Value</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">FreeSpace</span> <span class="sy0">=</span> Convert.<span class="me1">ToInt64</span><span class="br0">&#40;</span>row<span class="br0">&#91;</span>4<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">Name</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>5<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>row<span class="br0">&#91;</span>6<span class="br0">&#93;</span> <span class="sy0">!=</span> System.<span class="me1">DBNull</span>.<span class="me1">Value</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">Size</span> <span class="sy0">=</span> Convert.<span class="me1">ToInt64</span><span class="br0">&#40;</span>row<span class="br0">&#91;</span>6<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">Status</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>7<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">SystemName</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>8<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">VolumeName</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>9<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">DriveLetter</span> <span class="sy0">=</span> row<span class="br0">&#91;</span>5<span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">Substring</span><span class="br0">&#40;</span>0<span class="sy0">,</span> 2<span class="br0">&#41;</span>.<span class="me1">ToUpper</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; OutputWmiBuffer.<span class="me1">SetEndOfRowset</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<p>Now the data retrieved from the WQL Query can be transformed and loaded into SQL table to track the growth patterns of your servers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/10/18/using-the-wmi-reader-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS: Using the Script Component to Insert Rows and Retrieve Newly Created Keys</title>
		<link>http://www.mohenderson.com/2011/10/10/ssis-using-the-script-component-to-insert-rows-and-retrieve-newly-created-keys/</link>
		<comments>http://www.mohenderson.com/2011/10/10/ssis-using-the-script-component-to-insert-rows-and-retrieve-newly-created-keys/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 19:07:55 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Data Integration]]></category>
		<category><![CDATA[Database BI]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[SQL Server Management Objects]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://www.mohenderson.com/?p=175</guid>
		<description><![CDATA[In the last post I demonstrated using SQL Server Management Objects (SMO) to extract information on installed SQL Server instances. In this post the script component will be used as a transformation task,  addressing a common scenario of inserting rows &#8230; <a href="http://www.mohenderson.com/2011/10/10/ssis-using-the-script-component-to-insert-rows-and-retrieve-newly-created-keys/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the last post I demonstrated using SQL Server Management Objects (SMO) to extract information on installed SQL Server instances. In this post the script component will be used as a transformation task,  addressing a common scenario of inserting rows in a parent table, retrieve the newly created keys, and pass it along in the pipeline to be used with child tables.</p>
<p><strong>Data Model</strong></p>
<p>The data extracted will go into the database data warehouse I am developing. There are two tables involved in this <acronym>ETL</acronym>: a Data Store Object table and a SQL Server table. Similar to an order and order detail table, the Data Store Object table will contain some core data about the server such as name and create date. We’re talking information that’s not going to change once created. The SQL Server table will store details that could change over time.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/datamodelexcerpt.png" alt="Data Model Excerpt" width="205" height="348" /></p>
<p><strong>Using the Lookup Component</strong></p>
<p>After extracting the server information, use the lookup component to check if a server has already been added to the Data Store Object table. After the script component extracts the server information will, sort the data, and then add the Lookup component. In the transformation editor, specify non matches to <em>redirect</em> in the general section. In column section of the transformation editor, use the name column to join the two data sources, and add the Data Store Object table primary key. Rows that have been added in previous run will get assigned a key, and rows that need to be added will be null.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/lookuptransformation1.png" alt="lookuptransformation1" width="466" height="301" /></p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/lookuptransformation2.png" alt="lookuptransformation2" width="559" height="261" /></p>
<p><strong>Add Script Component.</strong></p>
<p>Add a script component to the data flow and select transformation as the component type. Send the <em>Lookup No Match Output</em> to this script component. In the input column select the columns needed to add a row to the Data Store Object table. Add the Data Store Object Table key as an output.</p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/scripttransformation1.png" alt="scripttransformation1" width="557" height="292" /></p>
<p><img class="ngg-singlepic ngg-none" style="border: 1px solid black;" src="http://www.mohenderson.com/wp-content/gallery/ssis_smo/scripttransformation2.png" alt="scripttransformation2" width="436" height="177" /></p>
<p>What this transformation is going to do the take the data on a new server and call a store procedure that inserts a new row in the database. The stored procedure will retrieve the newly created key and pass it back to SSIS in the form of an output parameter. The output column will be assigned the value of the output parameter.</p>
<div class="codesnip-container" >
<div class="c codesnip" style="font-family:monospace;">using System<span class="sy0">;</span><br />
using System.<span class="me1">Data</span><span class="sy0">;</span><br />
using System.<span class="me1">Data</span>.<span class="me1">SqlClient</span><span class="sy0">;</span><br />
using Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Pipeline</span>.<span class="me1">Wrapper</span><span class="sy0">;</span><br />
using Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Runtime</span>.<span class="me1">Wrapper</span><span class="sy0">;</span></p>
<p><span class="br0">&#91;</span>Microsoft.<span class="me1">SqlServer</span>.<span class="me1">Dts</span>.<span class="me1">Pipeline</span>.<span class="me1">SSISScriptComponentEntryPointAttribute</span><span class="br0">&#93;</span><br />
public class ScriptMain <span class="sy0">:</span> UserComponent<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; IDTSConnectionManager100 connMgr<span class="sy0">;</span><br />
&nbsp; &nbsp; SqlConnection conn<span class="sy0">;</span><br />
&nbsp; &nbsp; SqlCommand cmd<span class="sy0">;</span><br />
&nbsp; &nbsp; SqlParameter name<span class="sy0">;</span><br />
&nbsp; &nbsp; SqlParameter createDate<span class="sy0">;</span><br />
&nbsp; &nbsp; SqlParameter dataStoreObjectID<span class="sy0">;</span></p>
<p>
&nbsp; &nbsp; public override <span class="kw4">void</span> AcquireConnections<span class="br0">&#40;</span>object Transaction<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; base.<span class="me1">AcquireConnections</span><span class="br0">&#40;</span>Transaction<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; connMgr <span class="sy0">=</span> this.<span class="me1">Connections</span>.<span class="me1">DatabaseRepository</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; conn <span class="sy0">=</span> <span class="br0">&#40;</span>SqlConnection<span class="br0">&#41;</span>connMgr.<span class="me1">AcquireConnection</span><span class="br0">&#40;</span><span class="kw2">null</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; public override <span class="kw4">void</span> PreExecute<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; base.<span class="me1">PreExecute</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd <span class="sy0">=</span> new SqlCommand<span class="br0">&#40;</span><span class="st0">&quot;dso.DataStoreObject_InsertServer&quot;</span><span class="sy0">,</span> conn<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd.<span class="me1">CommandType</span> <span class="sy0">=</span> CommandType.<span class="me1">StoredProcedure</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; name <span class="sy0">=</span> new SqlParameter<span class="br0">&#40;</span><span class="st0">&quot;@Name&quot;</span><span class="sy0">,</span> SqlDbType.<span class="me1">NVarChar</span><span class="sy0">,</span> 128<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; name.<span class="me1">Direction</span> <span class="sy0">=</span> ParameterDirection.<span class="me1">Input</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span>name<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; createDate <span class="sy0">=</span> new SqlParameter<span class="br0">&#40;</span><span class="st0">&quot;@CreateDate&quot;</span><span class="sy0">,</span> SqlDbType.<span class="me1">DateTime</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; createDate.<span class="me1">Direction</span> <span class="sy0">=</span> ParameterDirection.<span class="me1">Input</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span>createDate<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; dataStoreObjectID <span class="sy0">=</span> new SqlParameter<span class="br0">&#40;</span><span class="st0">&quot;@DataStoreObjectID&quot;</span><span class="sy0">,</span> SqlDbType.<span class="me1">Int</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataStoreObjectID.<span class="me1">Direction</span> <span class="sy0">=</span> ParameterDirection.<span class="me1">Output</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span>dataStoreObjectID<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; public override <span class="kw4">void</span> InputServer_ProcessInputRow<span class="br0">&#40;</span>InputServerBuffer Row<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@Name&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> <span class="sy0">=</span> Row.<span class="me1">Name</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@CreateDate&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> <span class="sy0">=</span> Row.<span class="me1">CreateDate</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cmd.<span class="me1">ExecuteNonQuery</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; Row.<span class="me1">DataStoreObjectID</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span>cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@DataStoreObjectID&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; public override <span class="kw4">void</span> ReleaseConnections<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; base.<span class="me1">ReleaseConnections</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; connMgr.<span class="me1">ReleaseConnection</span><span class="br0">&#40;</span>conn<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</div>
<p><span style="color: #808080;"><strong><em>Note:</em></strong></span></p>
<p>I picked up many of the database interaction particulars from this post and would like recognize the author (<a href="http://www.mathgv.com/sql2005docs/SSISTransformScriptETL.htm">Greg Van Mullem</a>).</p>
<p><strong>Add Merge Component</strong></p>
<p>After the new objects have been added, combine with the existing objects using the merge component.</p>
<p><strong>Summary</strong></p>
<p>In the previous post I discussed using the script component in the extract portion of an ETL. In this post I demonstrated using the script component in the transformation, or T, in ETL. More importantly, the example steps through a common scenario of inserting rows in a database, get the newly created keys, and move along.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohenderson.com/2011/10/10/ssis-using-the-script-component-to-insert-rows-and-retrieve-newly-created-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

