<?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>Aaron Lowe &#187; SSIS</title>
	<atom:link href="http://www.aaronlowe.net/archive/category/ssis/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aaronlowe.net</link>
	<description>SELECT my.Thoughts FROM Vendoran.dbo.Brain my</description>
	<lastBuildDate>Fri, 23 Jul 2010 13:00:00 +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 CDC LSN Debugging nightmare second problem</title>
		<link>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-second-problem/</link>
		<comments>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-second-problem/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 09:00:00 +0000</pubDate>
		<dc:creator>Aaron Lowe</dc:creator>
				<category><![CDATA[2008]]></category>
		<category><![CDATA[CDC]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">/post/2009/12/18/SSIS-CDC-LSN-Debugging-nightmare-second-problem.aspx</guid>
		<description><![CDATA[Continuing the CDC debugging posts: Intro First Problem Now that I have the StartLSN and EndLSN I was ready to go.  Hit my breakpoint and the variables were set appropriately.  Woo-hoo! Then…wait a minute…what? vSQLQuery.Value = "SELECT " + " c.__$operation " + " , c.Column1 " + " , c.Column2 " + " , [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the CDC debugging posts:</p>
<ul>
<li><a href="http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-introduction/">Intro</a></li>
<li><a href="http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-first-problem/">First Problem</a></li>
</ul>
<p>Now that I have the StartLSN and EndLSN I was ready to go.  Hit my breakpoint and the variables were set appropriately.  Woo-hoo!</p>
<p>Then…wait a minute…what?</p>
<pre class="brush: csharp;">vSQLQuery.Value =
    "SELECT " +
    "    c.__$operation " +
    "    , c.Column1 " +
    "    , c.Column2 " +
    "    , ColumnN " +
    "FROM " +
    "    cdc.fn_cdc_get_net_changes_&lt;instance_name&gt;( " + sStartLSN + ",  " + sEndLSN + ", 'all') c";</pre>
<p>That statement wasn’t changing the value of vSQLQuery.  huh?</p>
<p>Ok, I don’t by any stretch of the imagination claim to be an expert at C# but that looked pretty straight forward to me, however it wasn’t changing the value.</p>
<p>So now I start looking in earnest, <a href="http://www.google.com" target="_blank">google</a>, <a href="http://www.bing.com" target="_blank">bing</a>, <a href="http://stackoverflow.com/" target="_blank">Stackoverflow</a>, <a href="http://serverfault.com/" target="_blank">Serverfault</a>, all to no avail.  This just wasn’t making sense.  I was about to call over an expert C# person (<a href="http://www.magenic.com" target="_blank">Magenic</a> is full of them <img src='http://www.aaronlowe.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) when I remembered that my previous problem was not a problem with the code but a problem with the configuration of the task.  So I start looking into the configuration of the script task and the variables that I was using and that’s where I saw it. </p>
<p>vSQLValue was set to evaluate as an expression.  I had done this so I could copy and paste the SQL query I had developed in SSMS as opposed to making the query 1 line and pasting it into the value of the variable (the variable box in SSIS can’t interpret multi-line values, it only pastes the first line).</p>
<p>Turned off the fact that it was an expression and since it had already been evaluated it set the variable correctly (score!) and now I could manipulate the vSQLQuery.Value via the script task.</p>
<p>Now as to why I couldn’t modify a variable that is set to evaluate as an expression, I don’t know I’m sure there’s some sort of order of operations or locking catch here, but I still haven’t been able to find anything official about this.  Best I saw was <a href="http://weblogs.sqlteam.com/dmauri/archive/2006/04/02/9489.aspx" target="_blank">this</a> which would indicate to me that it would work.</p>
<p>Onto the next problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-second-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS CDC LSN Debugging nightmare first problem</title>
		<link>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-first-problem/</link>
		<comments>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-first-problem/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 07:00:00 +0000</pubDate>
		<dc:creator>Aaron Lowe</dc:creator>
				<category><![CDATA[2008]]></category>
		<category><![CDATA[CDC]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">/post/2009/12/17/SSIS-CDC-LSN-Debugging-nightmare-first-problem.aspx</guid>
		<description><![CDATA[So now that we have the idea let’s look as the four main problems I encountered: The first problem I noticed was that the SQL query that was running still had nulls in on the StartLSN and EndLSN so I was querying: cdc.fn_cdc_get_net_changes_&#60;instance name&#62; (null, null, &#8216;all&#8217;) Which as I said last post, returns an [...]]]></description>
			<content:encoded><![CDATA[<p>So now that we have the idea let’s look as the four main problems I encountered:</p>
<p>The first problem I noticed was that the SQL query that was running still had nulls in on the StartLSN and EndLSN</p>
<p>so I was querying:</p>
<p>cdc.fn_cdc_get_net_changes_&lt;instance name&gt; (null, null, &#8216;all&#8217;)</p>
<p>Which as I said last post, returns an error. So throw a break point into the Script task and figure out why it’s not setting properly.&#160; This took me awhile, here’s the code:</p>
<pre class="brush: csharp;">var vStartLSN = Dts.Variables[&quot;User::sStartLSN&quot;];
var vEndLSN = Dts.Variables[&quot;User::sEndLSN&quot;];
var vSQLQuery = Dts.Variables[&quot;User::sSQLQuery&quot;];

string sStartLSN;
string sEndLSN;

Dts.VariableDispenser.LockForRead(&quot;User::sStartLSN&quot;);
Dts.VariableDispenser.LockForRead(&quot;User::sEndLSN&quot;);
Dts.VariableDispenser.LockForWrite(&quot;User::sSQLQuery&quot;);

sStartLSN = vStartLSN.Value.ToString();
sEndLSN = vEndLSN.Value.ToString();

vSQLQuery.Value =
    &quot;SELECT &quot; +
    &quot;    c.__$operation &quot; +
    &quot;    , c.Column1 &quot; +
    &quot;    , c.Column2 &quot; +
    &quot;    , ColumnN &quot; +
    &quot;FROM &quot; +
    &quot;    cdc.fn_cdc_get_net_changes_&lt;instance_name&gt;( &quot; + sStartLSN + &quot;,  &quot; + sEndLSN + &quot;, 'all') c&quot;;
Dts.Variables.Unlock();</pre>
<p>So hitting my first breakpoint, I first realized that the StartLSN variable was receiving a null.&#160; That wasn’t supposed to happen, so I looked at the SQL code I used to set the variables in the SQL Task:</p>
<p>SELECT sys.fn_cdc_get_min_lsn(&lt;instance_name&gt;) as @StartLSN</p>
<p>A-ha, that’s it. The function returns a record set and I had the task to just get a return value, not a record set.</p>
<p>So changed to:</p>
<p>SELECT @StartLSN = sys.fn_cdc_get_min_lsn(&lt;instance_name&gt;);<br />
  <br />SELECT @StartLSN as StartLSN</p>
<p>That got me past the first problem, now onto the next problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-first-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS CDC LSN Debugging nightmare introduction</title>
		<link>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-introduction/</link>
		<comments>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-introduction/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 07:00:00 +0000</pubDate>
		<dc:creator>Aaron Lowe</dc:creator>
				<category><![CDATA[2008]]></category>
		<category><![CDATA[CDC]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">/post/2009/12/16/SSIS-CDC-LSN-Debugging-nightmare-introduction.aspx</guid>
		<description><![CDATA[The other day I was working on an SSIS implementation that was utilizing Change Data Capture (CDC) to identify the source data that needed to be transformed into the destination.&#160; This is the first time that I had used CDC other than a quick demo and I was grateful to have Whitney’s help with understanding [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was working on an SSIS implementation that was utilizing <a href="http://msdn.microsoft.com/en-us/library/bb522489.aspx" target="_blank">Change Data Capture</a> (CDC) to identify the source data that needed to be transformed into the destination.&#160; This is the first time that I had used CDC other than a quick demo and I was grateful to have <a href="http://whitneyweaver.com/" target="_blank">Whitney’s</a> help with understanding some of the…shall we say eccentricities of CDC.</p>
<p>You can see <a href="http://www.codeplex.com/wikipage?ProjectName=MSFTISProdSamples&amp;title=SS2008!Change%20Data%20Capture%20since%20Last%20Request%20Package%20Sample" target="_blank">Change Data Capture since Last Request Package Sample</a> or <a href="http://www.codeplex.com/wikipage?ProjectName=MSFTISProdSamples&amp;title=SS2008!Change%20Data%20Capture%20for%20Specified%20Interval%20Package%20Sample" target="_blank">Change Data Capture for Specified Interval Package Sample</a> for the official MS examples which is the basis of what I was trying to accomplish, although in the specified interval sample they cheated by using a database snapshot to get the starting LSN and then just ran continuously from there keeping the LSNs in variables, they didn’t address the concept of true interval run that would be come to a stopping point and then start again after an interval passes.</p>
<p>So to give a little context to this post you need to understand some basics of SSIS and CDC.&#160; CDC utilizes <a href="http://msdn.microsoft.com/en-us/library/ms190411.aspx" target="_blank">Log Sequence Numbers</a> (LSNs) to know the start and stop point of the changes you are trying to identify.&#160; CDC is table based and logs those changes to an “instance” of the table that you specify, which is basically just a copy of the table DDL with a few added columns, the new table exists within the cdc schema and the table name is what you specify via the “instance name” parameter. You can track changes on the entire table or just specific columns, and there are functions to get all the changes or just the net changes.</p>
<p>Within CDC you have some very helpful system functions to assist with figuring out what LSNs you should be selecting, including:</p>
<ul>
<li>sys.fn_cdc_get_max_lsn      <br />sys.fn_cdc_get_min_lsn       <br />sys.fn_cdc_map_time_to_lsn       <br />sys.fn_cdc_map_lsn_to_time </li>
</ul>
<p>The other thing to remember is that LSNs are binary.&#160; In SSIS there is no variable type binary.&#160; The first odd thing I noticed (and this should have been a clue to the difficulties that lie ahead) was that the sys.fn_map_time_to_lsn has a strange parameter called the ‘relational operator’ and I kid you not these are the potential values:</p>
<ul>
<li>largest less than      <br />largest less than or equal       <br />smallest greater than       <br />smallest greater than or equal </li>
</ul>
<p>Yes the actual text strings are what is needed to be entered there.&#160; The idea being that LSNs aren’t directly time related to so you need to specify the relationship in relation to the datetime your passing.&#160; </p>
<p>The next&#160; thing I noticed that is strange was that sys.fn_cdc_get_min_lsn must be instance specific, while sys.fn_cdc_get_max_lsn is the entire server.&#160; So hopefully this will be a little more straight forward in the next version. &lt;TangentRant&gt;although that’s what I thought about Service Broker which I love, but sadly still isn’t that straight forward, however that’s for another post&lt;/TangentRant&gt;&#160; </p>
<p>So to cover all bases this was my process:</p>
<p>1.) The parent package would get the LSN boundaries based upon the last successful run of the package (StartLSN) and the current run (EndLSN), passing those variables to the children packages.</p>
<p>2.) The child package which is instance specific, would then verify that that StartLSN was not less than the minimum LSN for that instance, if it was, than use the MinLSN instead.&#160; </p>
<p>3.) Utilize the TVF to get the net changes cdc.fn_cdc_get_net_changes_&lt;capture_instance&gt; (to get all changes you would use cdc.fn_cdc_get_all_changes_&lt;capture_instance&gt;)    </p>
<p>A couple other issues here when using with SSIS here:</p>
<p>1.) It’s a TVF so if you pass bad parameters as start and end LSNs, you get an error in addition to the column header information:</p>
<p>“An insufficient number of arguments were supplied for the procedure or function cdc.fn_cdc_get_net_changes_ &#8230; .”</p>
<p>2.) It’s a TVF so you can’t use it as an OLEDB data source, instead you have to use an ssis variable as the data source, which mean the query needs to be set with the proper query with null values for the Start and End LSNs (remember even though it brings back an error it will bring back column information).&#160; This also means the script task is needed to change the alter the query string variable to substitute the proper start and end LSNs at runtime.</p>
<p>So now that we have the basis of what I was doing, now onto the debugging…</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlowe.net/archive/2009/12/ssis-cdc-lsn-debugging-nightmare-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSIS Blog Post Thank you</title>
		<link>http://www.aaronlowe.net/archive/2009/01/ssis-blog-post-thank-you/</link>
		<comments>http://www.aaronlowe.net/archive/2009/01/ssis-blog-post-thank-you/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 20:29:41 +0000</pubDate>
		<dc:creator>Aaron Lowe</dc:creator>
				<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">/post/2009/01/26/SSIS-Blog-Post-Thank-you.aspx</guid>
		<description><![CDATA[Traditionally I have used SSIS for OLTP data movements, however lately I’ve been loading a Data Warehouse which has slightly different requirements.&#160; I just wanted to drop a quick note to highlight the great resources that already exist out there (and thanks to Dan English for pointing me to most of them).&#160; These have been [...]]]></description>
			<content:encoded><![CDATA[<p>Traditionally I have used SSIS for OLTP data movements, however lately I’ve been loading a Data Warehouse which has slightly different requirements.&#160; I just wanted to drop a quick note to highlight the great resources that already exist out there (and thanks to <a href="http://denglishbi.spaces.live.com/">Dan English</a> for pointing me to most of them).&#160; These have been very helpful and I recommend them if you are using SSIS to load a Data Warehouse.&#160; And to the authors &#8211; thanks for the posts, they have been very helpful!</p>
<ul>
<li><a href="http://sqlcat.com/top10lists/archive/2008/10/01/top-10-sql-server-integration-services-best-practices.aspx">Top 10 SQL Server Integration Services Best Practices</a> </li>
<li><a href="http://microsoft-business-intelligence.blogspot.com/2008/11/scd-slowly-changing-dimension.html">SCD (Slowly Changing Dimension) optimization in SSIS</a> </li>
<li><a href="http://sqlblogcasts.com/blogs/jorg/archive/2008/10/22/ssis-decrease-your-fact-table-loading-time-up-to-40.aspx">SSIS &#8211; Decrease your fact table loading time up to 40%</a> </li>
<li><a href="http://blogs.conchango.com/jamiethomson/archive/2005/06/11/SSIS_3A00_-Custom-Logging-Using-Event-Handlers.aspx">SSIS: Custom Logging Using Event Handlers</a> </li>
<li><a href="http://sqlblog.com/blogs/andy_leonard/archive/tags/ETL+Instrumentation/default.aspx">SSIS Design Pattern &#8211; ETL Instrumentation</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlowe.net/archive/2009/01/ssis-blog-post-thank-you/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
