Jamie Thomson : Parametershttp://sqlblog.com/blogs/jamie_thomson/archive/tags/Parameters/default.aspxTags: ParametersenCommunityServer 2.1 SP2 (Build: 61129.1)Using Find/Replace with regular expressions inside a SSIS packagehttp://sqlblog.com/blogs/jamie_thomson/archive/2012/06/12/using-find-replace-with-regular-expressions-inside-a-ssis-package.aspxTue, 12 Jun 2012 08:56:37 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:43845jamiet2http://sqlblog.com/blogs/jamie_thomson/comments/43845.aspxhttp://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=43845http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=43845<p><em>Another one of those might-be-useful-again-one-day-so-I’ll-share-it-in-a-blog-post blog posts</em></p> <p>I am currently working on a SQL Server Integration Services (SSIS) 2012 implementation where each package contains a parameter called ETLIfcHist_ID:</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_175EF134.png"><img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_1B1C9604.png" width="377" height="135" /></a></p> </blockquote> <p>During normal execution this will get altered when the package is executed from the Execute Package Task however we want to make sure that at deployment-time they all have a default value of –1. Of course, they tend to get changed during development so I wanted a way of easily changing them all back to the default value. Opening up each package in turn and editing them was an option but given that we have over 40 packages and we might want to carry out this reset fairly frequently I needed a more automated method so I turned to Visual Studio’s Find/Replace… feature</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_19D7FD25.png"><img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_318F348B.png" width="427" height="302" /></a></p> </blockquote> <p>Of course, we don’t know what value will be in that parameter so I can’t simply search for a particular value; hence I opted to use a regular expression to identify the value to be change. In the rest of this blog post I’ll explain how to do that.</p> <p>For demonstration purposes I have taken the contents of a .dtsx file and stripped out everything except the element containing the parameters (<span style="color:;"><font color="#0000ff">&lt;</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameters</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>), if you want to play along at home you can copy-paste the XML document below into a new XML file and open it up in Visual Studio:</p> <blockquote> <pre style="text-align:left;list-style-type:disc;font-family:;background:white;color:;"><font face="Consolas"><span style="color:;"><font color="#0000ff"><font style="font-size:9.8pt;">&lt;?</font></font></span><font style="font-size:9.8pt;"><span style="color:;"><font color="#a31515">xml</font></span><span style="color:;"><font color="#0000ff">&#160;</font></span><span style="color:;"><font color="#ff0000">version</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">1.0</font></span>&quot;<span style="color:;"><font color="#0000ff">?&gt;</font></span>
<span style="color:;"><font color="#0000ff">&lt;</font></span><span style="color:;"><font color="#a31515">DTS:Executable</font></span><span style="color:;"><font color="#0000ff">&#160;</font></span><span style="color:;"><font color="#ff0000">xmlns:DTS</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">www.microsoft.com/SqlServer/Dts</font></span>&quot;<span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160; &lt;</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameters</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160; &lt;</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameter</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:CreationName</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DataType</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">3</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:Description</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">InterfaceHistory_ID: used for Lineage</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DTSID</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">{635616DB-EEEE-45C8-89AA-713E25846C7E}</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:ObjectName</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">ETLIfcHist_ID</font></span>&quot;<span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; &lt;</font></span><span style="color:;"><font color="#a31515">DTS:Property</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DataType</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">3</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:Name</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">ParameterValue</font></span>&quot;<span style="color:;"><font color="#0000ff">&gt;</font></span>VALUE_TO_BE_CHANGED<span style="color:;"><font color="#0000ff">&lt;/</font></span><span style="color:;"><font color="#a31515">DTS:Property</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160; &lt;/</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameter</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160; &lt;</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameter</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:CreationName</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DataType</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">3</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:Description</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">Some other description</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DTSID</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">{635616DB-EEEE-45C8-89AA-713E25845C7E}</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:ObjectName</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">SomeOtherObjectName</font></span>&quot;<span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; &lt;</font></span><span style="color:;"><font color="#a31515">DTS:Property</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DataType</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">3</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:Name</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">ParameterValue</font></span>&quot;<span style="color:;"><font color="#0000ff">&gt;</font></span>SomeOtherValue<span style="color:;"><font color="#0000ff">&lt;/</font></span><span style="color:;"><font color="#a31515">DTS:Property</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160; &lt;/</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameter</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160; &lt;/</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameters</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&lt;/</font></span><span style="color:;"><font color="#a31515">DTS:Executable</font></span></font><span style="color:;"><font style="font-size:9.8pt;" color="#0000ff">&gt;</font></span></font></pre>
</blockquote>
<p>We are trying to identify the value of the parameter whose name is ETLIfcHist_ID – notice that in the XML document above that value is VALUE_TO_BE_CHANGED. The following regular expression will find the appropriate portion of the XML document:</p>
<blockquote>
<p><font style="background-color:#a5a5a5;"><strong><u>{</u></strong>\&lt;DTS\:PackageParameter[\n ]*DTS\:CreationName=&quot;[A-Za-z0-9\:_\{\}- ]*&quot;[\n ]*DTS\:DataType=&quot;[A-Za-z0-9\:_\{\}- ]*&quot;[\n ]*DTS\:Description=&quot;[A-Za-z0-9\:_\{\}- ]*&quot;[\n ]*DTS\:DTSID=&quot;[A-Za-z0-9\:_\{\}- ]*&quot;[\n ]*DTS\:ObjectName=&quot;<strong><u>ETLIfcHist_ID</u></strong>&quot;\&gt;[\n ]*\&lt;DTS\:Property[\n ]*DTS\:DataType=&quot;[A-Za-z0-9\:_\{\}- ]*&quot;[\n ]*DTS\:Name=&quot;ParameterValue&quot;\&gt;<strong><u>}</u></strong></font>[A-Za-z0-9\:_\{\}- ]*<font style="background-color:#a5a5a5;"><strong><u>{</u></strong>\&lt;\/DTS\:Property\&gt;<strong><u>}</u></strong></font></p>
</blockquote>
<p>I have <u><strong>highlighted</strong></u> the name of the parameter that we’re looking for. I have also <font style="background-color:#a5a5a5;">highlighted</font> two portions identified by pairs of curly braces “<strong><u>{</u></strong>…<strong><u>}</u></strong>”; these are important because they pick out the two portions <em>either side</em> of the value I want to replace, in other words the portions <font style="background-color:#a5a5a5;">highlighted</font> here:</p>
<blockquote>
<pre style="text-align:left;list-style-type:disc;font-family:;background:white;color:;"><font face="Consolas"><span style="color:;"><font color="#0000ff"><font style="font-size:9.8pt;">&lt;</font></font></span><font style="font-size:9.8pt;"><span style="color:;"><font color="#a31515">DTS:PackageParameters</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160; <font style="background-color:#a5a5a5;">&lt;</font></font></span><font style="background-color:#cccccc;"><font style="background-color:#a5a5a5;"><span style="color:;"><font color="#a31515">DTS:PackageParameter</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:CreationName</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DataType</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">3</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:Description</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">InterfaceHistory_ID: used for Lineage</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DTSID</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">{635616DB-EEEE-45C8-89AA-713E25846C7E}</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:ObjectName</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">ETLIfcHist_ID</font></span>&quot;<span style="color:;"><font color="#0000ff">&gt;</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160; &lt;</font></span><span style="color:;"><font color="#a31515">DTS:Property</font></span>
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:DataType</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">3</font></span>&quot;
<span style="color:;"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color:;"><font color="#ff0000">DTS:Name</font></span><span style="color:;"><font color="#0000ff">=</font></span>&quot;<span style="color:;"><font color="#0000ff">ParameterValue</font></span>&quot;<span style="color:;"><font color="#0000ff">&gt;</font></span></font><font style="background-color:#ffffff;">VALUE_TO_BE_CHANGED</font></font><font style="background-color:#a5a5a5;"><span style="color:;"><font color="#0000ff">&lt;/</font></span><span style="color:;"><font color="#a31515">DTS:Property</font></span><span style="color:;"><font color="#0000ff">&gt;</font></span>
</font><span style="color:;"><font color="#0000ff">&#160;&#160;&#160; &lt;/</font></span><span style="color:;"><font color="#a31515">DTS:PackageParameter</font></span></font><span style="color:;"><font style="font-size:9.8pt;" color="#0000ff">&gt;</font></span></font></pre>
</blockquote>
<p>Those sections in the curly braces are termed tag expressions and can be identified in the replace expression using a backslash and a number identifying which tag expression you’re referring to according to its ordinal position. Hence, our replace expression is simply:</p>
<blockquote>
<p><font style="background-color:#a5a5a5;">\1</font>-1<font style="background-color:#a5a5a5;">\2</font></p>
</blockquote>
<p>We’re saying the portion of our file identified by the regular expression should be replaced by the first curly brace section, then the literal –1, then the second curly brace section. Make sense? Give it a go yourself by plugging those two expressions into Visual Studio’s Find and Replace dialog. If you set it to look in “All Open Documents” then you can open up the code-behind of all your packages and change all of them at once. The Find and Replace dialog will look like this:</p>
<blockquote>
<p><a href="http://sqlblog.com/blogs/jamie_thomson/image_64EAF7E7.png"><img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_4AAA8EC3.png" width="348" height="325" /></a></p>
</blockquote>
<p>That’s it! I realise that not everyone will be looking to change the value of a parameter but hopefully I have shown you a technique that you can modify to work for your own scenario.</p>
<p>Given that this blog post is, y’know, on the web I have no doubt that someone is going to find a fault with my find regex expression and if that person is you….that’s OK. Let me know about it in the comments below and perhaps we can work together to come up with something better! Note that some parameters may have a different set of properties (for example some, but not all, of my parameters have a <font face="Consolas"><span style="color:;"><font color="#800000"><font style="font-size:9.8pt;">DTS:Required</font></font></span></font> attribute) so your find regular expression may have to change accordingly.</p>
<p>When researching this I found the following article to be invaluable: <a href="http://www.codeproject.com/Articles/18101/Visual-Studio-Find-Replace-Regular-Expression-Usag" target="_blank">Visual Studio Find/Replace Regular Expression Usage</a></p>
<p><a href="http://twitter.com/jamiet" target="_blank">@Jamiet</a></p><img src="http://sqlblog.com/aggbug.aspx?PostID=43845" width="1" height="1">sql serversql server integration servicesssisRegexParametersRegular ExpressionsRequired Parameters [SSIS Denali]http://sqlblog.com/blogs/jamie_thomson/archive/2010/12/20/required-parameters-ssis-denali.aspxMon, 20 Dec 2010 17:35:10 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:31795jamiet1http://sqlblog.com/blogs/jamie_thomson/comments/31795.aspxhttp://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=31795http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=31795<p>SQL Server Integration Services (SSIS) in its 2005 and 2008 incarnations expects you to set a property values within your package at runtime using Configurations. SSIS developers tend to have rather a lot of issues with SSIS configurations; in this blog post I am going to highlight one of those problems and how it has been alleviated in SQL Server code-named Denali.</p> <p>&#160;</p> <p>A configuration is a property path/value pair that exists outside of a package, typically within SQL Server or in a collection of one or more configurations in a file called a .dtsConfig file. Within the package one defines a pointer to a configuration that says to the package “When you execute, go and get a configuration value from this location” and if all goes well the package will fetch that configuration value as it starts to execute and you will see something like the following in your output log:</p> <blockquote> <p><font face="Consolas">Information: 0x40016041 at Package: The package is attempting to configure from the XML file &quot;C:\Configs\MyConfig.dtsConfig&quot;.</font></p> </blockquote> <p>Unfortunately things DON’T always go well, perhaps the .dtsConfig file is unreachable or the name of the SQL Sever holding the configuration value has been defined incorrectly – any one of a number of things can go wrong. In this circumstance you might see something like the following in your log output instead:</p> <blockquote> <p><font face="Consolas">Warning: 0x80012014 at Package: The configuration file &quot;C:\Configs\MyConfig.dtsConfig&quot; cannot be found. Check the directory and file name.</font></p> </blockquote> <p>The problem that I want to draw attention to here though is that <em><strong>your package will ignore the fact it can’t find the configuration and executes anyway</strong></em>. This is really really bad because the package will not be doing what it is supposed to do and worse, if you have not isolated your environments you might not even know about it. Can you imagine a package executing for months and all the while inserting data into the wrong server? Sounds ridiculous but I have absolutely seen this happen and the root cause was that no-one picked up on configuration warnings like the one above.</p> <p>Happily in SSIS code-named Denali this problem has gone away as configurations have been replaced with <a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/11/11/parameters-in-ssis-in-denali.aspx">parameters</a>. Each parameter has a property called ‘Required’:</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_1E13F054.png"><img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_2D675263.png" width="543" height="107" /></a></p> </blockquote> <p>Any parameter with Required=True must have a value passed to it when the package executes. Any attempt to execute the package will result in an error. Here we see that error when attempting to execute using the SSMS UI:</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_65399686.png"><img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_6AA8072A.png" width="685" height="464" /></a></p> </blockquote> <p>and similarly when executing using T-SQL:</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_5AB8C266.png"><img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_59742987.png" width="754" height="335" /></a></p> <p>Error is:</p> <p><font color="#ff0000">Msg 27184, Level 16, State 1, Procedure prepare_execution, Line 112 <br />In order to execute this package, you need to specify values for the required parameters. <br /></font></p> </blockquote> <p>&#160;</p> <p>As you can see, SSIS code-named Denali has mechanisms built-in to prevent the problem I described at the top of this blog post. Specifying a Parameter required means that any packages in that project <strong><em>cannot execute until a value for the parameter has been supplied</em></strong>. This is a very good thing.</p> <p>I am loathe to make recommendations so early in the development cycle but right now I’m thinking that all Project Parameters should have Required=True, certainly any that are used to define external locations should be anyway.</p> <p><a href="http://twitter.com/jamiet">@Jamiet</a></p><img src="http://sqlblog.com/aggbug.aspx?PostID=31795" width="1" height="1">sql serversql server integration servicesssisdenaliParametersSQL Server 2012Parameters in SSIS in Denalihttp://sqlblog.com/blogs/jamie_thomson/archive/2010/11/11/parameters-in-ssis-in-denali.aspxThu, 11 Nov 2010 19:58:00 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:30436jamiet18http://sqlblog.com/blogs/jamie_thomson/comments/30436.aspxhttp://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=30436http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=30436<p>In my last blog post <a target="_blank" href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/11/10/introduction-to-ssis-projects-in-denali.aspx">Introduction to SSIS Projects in Denali</a> I talked about the new Project deployment model that is coming in the next version of SQL Server Integration Services (SSIS); working hand-in-hand with Projects is another new feature – Parameters. Parameters are similar to Variables in SSIS today that we all know and (ahem) love but with one important difference – they are fundamental to how SSIS will manage and execute packages inside a SSIS Catalog (we’ll get onto those later) and hence have some subtle differences to Variables. Moreover (this should please a lot of you), <b>parameters are the replacement for configurations</b> that are in the current version of SSIS (i.e. SSIS2008).</p> <p>There are two types of parameters:</p> <ul> <li>Project parameters </li> <li>Package parameters </li> </ul> <p>I’ll be covering both herein.</p> <p>First there is a little bit of terminology to be grasped in regard to parameters. As with all terminology please learn these and use them appropriately:</p> <ol> <li><b>Design Default: </b>The value that gets set for a parameter at design-time </li> <li><b>Server Default: </b>Optional new default value that is applied to the parameter when it is deployed to a catalog. </li> <li><b>Execution Parameter Value:</b> Effectively an override for the Server default that you set when the package is executed </li> </ol> <p>There are a few more things to know about Parameters in regard to Catalogs and Environments (another new term) but as I haven’t talked about Environments yet I’ll save that for later.</p> <p>Parameters can be read from and written to inside a package and by implication they can also be referenced by any task in those packages. References will be in an expression just as is the case with Variables, they just happen to have a slightly different syntax as shown here:</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_0B072546.png"><img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" width="575" height="508" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_1AC6BA4A.png"></a></p> </blockquote> <p>Simply a prefix of either $Project or $Package (as appropriate) can be applied to a parameter name to reference it in an expression. I have highlighted a Package Parameter and two Project Parameters available in the familiar Expression Builder in the screenshot above.</p> <h1>Project Parameters</h1> <p>As I said above Parameters are very similar to Variables but in the case of <i>Project </i>Parameters there is one very important characteristic that distinguishes them - <b>instead of being scoped to a package they are scoped to a <i>Project</i> and any package within that project can access them</b>. (This is why its important to have a good grasp of SSIS Projects before being introduced to Parameters and hence why my first post in this series was <a target="_blank" href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/11/10/introduction-to-ssis-projects-in-denali.aspx">Introduction to SSIS Projects in Denali</a>). With that in mind let’s take a closer look at Project Parameters. </p> <p>Right-clicking on a project in Solution Explorer will offer the option to display the parameters of that project:</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_267C017C.png"><img style="background-image:none;border-right-width:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" width="439" height="180" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_507BFFA4.png"></a></p> </blockquote> <p>selecting that option displays the Project Parameters pane:</p> <blockquote> <p><a href="http://sqlblog.com/blogs/jamie_thomson/image_4AFD6933.png"><img style="background-image:none;border-right-width:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" width="566" height="117" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_22EABA14.png"></a></p> </blockquote> <p>In the example shown here I have a CustomerId parameter that can be accessed by any package within the project.</p> <ul> <li><b>Scope</b>, in the case of Project Parameters, is always “Project”'</li> <li><b>Data Type </b>is, hopefully, self-explanatory</li> <li><b>Default Value</b><u> </u>is the <b>Design Default</b> that I mentioned earlier</li> <li>Setting <b>Sensitive on server </b>to TRUE will ensure that the the value in the parameter gets encrypted when it is deployed to a SSIS catalog (important for secure credentials)</li> <li>Setting <b>Required</b><u> </u>to TRUE means that after the project is deployed a <b>Server Default </b>or <b>Execution Parameter Value</b> must be supplied.</li> </ul> <p>The ability to be accessed across multiple packages in a project is important. SSIS developers today will be well used to various mechanisms to using a value in multiple packages; Parent Package Configurations are a common option as is referencing the same configuration file from multiple packages although, judging by the amount of posts on the <a target="_blank" href="http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/threads">SSIS forum</a>, neither of these options are particularly well-liked amongst the SSIS fraternity. <i>Writing </i>to a Variable from multiple packages is even more difficult, indeed sometimes the only way to do it means <a target="_blank" href="http://consultingblogs.emc.com/jamiethomson/archive/2005/03/17/1151.aspx">resorting to writing script code</a> – not quick and easy at all. Project Parameters change all that because they are defined <i>outside</i> of a package hence can be accessed by any package within the Project and this makes them ideal for storing such things as database connection strings. its not hard to see why they are going to be a great replacement for configurations.</p> <h1>Package Parameters</h1> <p>Pretty much everything I just said about Project Parameters applies to Package Parameters except for one important difference and that is implied by the name – they are scoped to a Package rather than a Project. If you’re now asking yourself “What’s the difference between Package Parameters and package-scoped Variables?” then you’re not alone, I was asking myself the same thing. Aside from what I already said about Project Parameters (able to be referenced inside a Catalog etc…) the distinguishing characteristic (and what makes them useful) as far as I can discern is that they can be referenced from an Execute Package Task thus solving the problems that I outlined in my Connect submission <a target="_blank" href="https://connect.microsoft.com/SQLServer/feedback/details/295885/ssis-execute-package-task-should-support-parameters">Execute Package Task should support parameters</a> – indeed someone from the SSIS team replied to that submission by saying:</p> <blockquote> <p><i>We have introduced parameters in upcoming release, and parent package will be able to use parent parameters to set the child package parameter values. Child package will also be able to run on its own. Hopefully this will address most of the issues described in this bug. </i></p> </blockquote> <p>For folks that don’t want to move to the new deployment model (which isn’t a pre-requisite to using SSIS in Denali by the way) the ability to parameterize the Execute Package Task is a great new feature. More on the new Execute Package Task in a later blog post.</p> <p>&nbsp;</p> <p>I think I have exhausted SSIS Parameters for now. In this blog post I introduced some terminology that I haven’t covered yet, namely Catalogs and Environments. I’ll cover those in a later blog post.</p> <p><a href="http://twitter.com/jamiet">@Jamiet</a></p><p>UPDATE: I want to make a clarification about a statement I said above that some people may have misinterpreted. Configurations as you know them today are not going away -they are fully supported in Denali- now though you have the option to use parameters instead. So, for those of you that may be fretting that your existing SSIS implementations will not work in Denali, fear not - barring any other unforeseen mishaps they should continue to work just fine.</p><img src="http://sqlblog.com/aggbug.aspx?PostID=30436" width="1" height="1">sql serversql server integration servicesssisdenaliParametersSQL Server 2012