<?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>www.wiseinn.com</title>
	<atom:link href="http://www.wiseinn.com/index.php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wiseinn.com</link>
	<description></description>
	<lastBuildDate>Wed, 19 Oct 2011 08:08:56 +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>What is Google Sandbox?</title>
		<link>http://www.wiseinn.com/index.php/others/seo/what-is-google-sandbox</link>
		<comments>http://www.wiseinn.com/index.php/others/seo/what-is-google-sandbox#comments</comments>
		<pubDate>Sun, 02 Oct 2011 23:34:35 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1989</guid>
		<description><![CDATA[&#160; What is Google Sandbox? What is otherwise known as the Sandbox Effect, it is a simple idea that is explains why some sites who are trying to get ranked in the search engines don&#8217;t get indexed at all. For example, if you just built a site and you know that the spider has been [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="color: rgb(66, 81, 99); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: rgb(191, 200, 215); ">
<h1 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: rgb(82, 105, 132); color: rgb(189, 203, 214); text-indent: 5px; ">What is Google Sandbox?</h1>
<p>What is otherwise known as the Sandbox Effect, it is a simple idea that is explains why some sites who are trying to get ranked in the search engines don&#8217;t get indexed at all. For example, if you just built a site and you know that the spider has been to your site and you get zero search engine ranking , it is said that your site got sent to the sandbox. The sandbox is a holding area that Google has, some sites are held their until Google decides the site can be ranked.</p>
<p>There are some criticism of the sandbox, some webmasters do not think it exists and when a site does not get indexed it is due to a algorithm rather than a policy from Google stating all sites that are not ready to be indexed be placed in a sandbox. It should be noted that everyone is in agreement that the sandbox is only associated with Google and the other search engines such as Yahoo and MSN remain un-phased.</p>
<h1 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: rgb(82, 105, 132); color: rgb(189, 203, 214); text-indent: 5px; ">Poor SEO</h1>
<p>The reason why a site may be placed in the sandbox would be because the site has too much spam on it , the site is not user friendly, the content is not unique enough or there are too many ads and not enough content. There is a website called Searchguild.com they have started a test site that figures out why a site would be placed in the sandbox. It also was created to help tell apart sandbox sites from poor SEO or if a site has too much spam. They help you determine why your page results have been established by Google as being not good enough to index.</p>
<p>Depending on why your site may have been placed in the sandbox it could be a long period of time before the spiders are sent again. In the meantime, you can take at look at your site or have a professional look at it and try to figure out why it was sandboxed. You have time to improve the site, if you revamp your site when the spider comes again you may have corrected the mistake and you could get indexed the second time around. Other sites may take longer if you don&#8217;t choose to fix them.</p>
<p>The Google Sandbox is believed to be placed in effect around March of 2004. The sandbox does not have anything to do with end users looking for content on some of the more well known sites, it may however impact users who are looking for more current, one of a kind information that can only be found in newly created sites that have been placed in the sandbox.</p>
<p>Some believe that the sandbox has been put in place for Google to help separate the spam sites that try to cheat their way through SEO to get a better page rank. Some sites get barred by Google for that reason and some webmasters even go as far as using a different domain using the same practice. Others believe that the sandbox is a matter of time it takes the search engine to examine the site and figure out a page rank and for whatever reason was placed in holding until the search engine can determine a page rank.</p>
<p>All in all you may never know the reason why the site was placed in the sandbox, but if you get the chance, sit down and review your site and make changes because you were placed in the sandbox for a reason, may be you will get lucky on the second spider crawl.</p>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/others/seo/what-is-google-sandbox/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is webmaster?</title>
		<link>http://www.wiseinn.com/index.php/others/seo/what-is-webmaster</link>
		<comments>http://www.wiseinn.com/index.php/others/seo/what-is-webmaster#comments</comments>
		<pubDate>Sun, 02 Oct 2011 09:12:19 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1986</guid>
		<description><![CDATA[&#160; A webmaster is the creator of a website. These are people who design and create their own sites. A webmaster can either work for themselves creating sites to make money from or them can work as a webmaster for another company. Webmasters have many tasks to do in their profession. In addition to creating [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<div><span class="Apple-style-span" style="color: rgb(66, 81, 99); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: rgb(191, 200, 215); ">
<p>A webmaster is the creator of a website. These are people who design and create their own sites. A webmaster can either work for themselves creating sites to make money from or them can work as a webmaster for another company. Webmasters have many tasks to do in their profession. In addition to creating a website they are also responsible for maintenance. About 25 percent of webmasters day will consist of performing maintenance on a site. Maintenance includes updating or adding content, adding new offers as well as removing any old offers that are not making any money.</p>
<p>A webmaster also perform programming tasks. About 40 percent of a webmasters time is dedicated to programming , some sites use Perl and others use C programming. A webmaster&#8217;s job as a programmer involves rewriting the site at times or adding in new programs or removing existing programs. A part of a webmasters job is a developer. In this task, the webmaster will focus on creating new pages and developing new ideas and writing new content.</p>
<p>A webmaster can also be a graphic designer if they are a jack of all trades. They can create new graphics for the site and if they are independent webmasters they can create new graphics for their sites as well as freelancing for others. You must be familiar with Adobe Photoshop with Illustrator which is a favorite among webmasters with graphic design experience.</p>
<p>Webmasters also perform server maintenance, either for themselves or for a company, sometimes the server that the sites are on need to be updated for have some preventative maintenance done. These sites and all of the webmasters work has to be backed up in case of a crash and you want the server to be holding these files to be in perfect working order. A major duty of a professional webmaster is called Release Engineering. This is where a webmaster develops and takes the scripts that move the web pages from the creation server to the production server. Source codes control systems must be maintained and the system should be checked for viruses and bugs.</p>
<p>Overall a webmaster must know HTML for coding, CGI, Perl or C programming, they must posses artistic ability especially graphic artist ability. A webmaster must know how to write properly in order to create content for their site. They should know others programming such as Java Script, Flash or Ajax. They must be knowledgeable in server side programming that includes SSI, ASP, PHP and Cold Fusion. They also must know database knowledge for sites that carry databases.</p>
<p>If you want the more abstract definition of what a webmaster is, is they are web site creators that use online media methods to sell products or provide a service. When a webmaster works purely for themselves they can either create a web site that they are going to keep for themselves and monetize it for income or they are going to freelance and create web sites for customer for a specific price.</p>
<p>Either way they must have the skills to be an all around webmaster , someone who knows the task at hand from A to Z. With new technologies coming out all the time, the webmaster must keep on top of all the latest programs and on all the latest changes in the existing programs. That is what makes a successful webmaster. Other names for webmasters are webmistress as the feminine version, they are called web designers, web site administrator and system administrator. There are trade school and college courses you can take if you are interested in becoming a webmaster or you can be adventurous and become a self taught webmaster.</p>
</span></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/others/seo/what-is-webmaster/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is a Link Exchange?</title>
		<link>http://www.wiseinn.com/index.php/others/seo/what-is-a-link-exchange</link>
		<comments>http://www.wiseinn.com/index.php/others/seo/what-is-a-link-exchange#comments</comments>
		<pubDate>Sun, 02 Oct 2011 09:07:26 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1984</guid>
		<description><![CDATA[&#160; What is a Link Exchange? A link exchange is a method of trading links with other web sites. There is more than one way to set up a link exchange with other webmasters, the most common way is to go to a site and go to the contact us and send the webmaster an [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="color: rgb(66, 81, 99); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: rgb(191, 200, 215); ">
<h1 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: rgb(82, 105, 132); color: rgb(189, 203, 214); text-indent: 5px; ">What is a Link Exchange?</h1>
<p>A link exchange is a method of trading links with other web sites. There is more than one way to set up a link exchange with other webmasters, the most common way is to go to a site and go to the contact us and send the webmaster an email and request a link exchange. If linking their site with yours will increase their traffic then you will get a yes, but if your site and there are totally two different things and you don&#8217;t all that much traffic then you may get a polite No Thanks.</p>
<p>Link exchanges have been going on since the inception of the World Wide Web. After 2000, link exchanges have become more and more popular. The reason for the popularity is due to the fact that Google has increased the ranking of sites who tend to link exchange over those who don&#8217;t. Some internet expert today think that search engines really don&#8217;t favor link exchanges over those who don&#8217;t anymore. It was favorable when Google was on it sway to becoming the giant they are today. Today&#8217;s sites are gauged by one way incoming links to a particular site.</p>
<p>It is also more important these days that when you have a link exchange that the other site that you are linking to has some significance to your site. For example, if you have a dog site and you decide to link exchange with a site that is all about pickles then the search engines may not find that favorable. But if the link exchange was with a cats site then that would be acceptable. If you are considering link exchanges then you want to share a links with a site that is similar or associated to yours, otherwise it may affect your search engine ranking .</p>
<p>You could seal the deal with a site that happens to be in the same industry as the one you are like. Some webmasters may not wish to link exchange with their competitors which is their loss but you can find sites that will complement your site as well as theirs. When you send a webmaster an email requesting a link exchange, outline the positives as to why link exchanges with you can be beneficial to you.</p>
<p>There are link exchange directories available with a list of sites that are looking for other sites to link exchange with. Some of the web link directories charge a fee in order to gain access to their databases. There are some free web link directories that are free, you just have to search for them. The upside of link exchanging is to increase your traffic , as you go about contacting other sites to exchanging links do a search for them on Alexa, it will give you all the information you need in order to find out if this is a site that you wish to link to.</p>
<p>By linking to the wrong sites can really prove to be a negative situation for you. The best way to exchange links is to uphold a strict lining process that does not wish to accept other links from any sites that do not have anything directly related to your site. Remember it is your site and whether or not you decide to exchange links is strictly up to you. If you are thinking about it , just do your research before you exchange the link, find out what their rank is in the search engine and get an actual number of traffic ask the webmaster about their traffic and verify through Alexa.</p>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/others/seo/what-is-a-link-exchange/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Major SEO Popular Tools</title>
		<link>http://www.wiseinn.com/index.php/others/seo/major-seo-popular-tools</link>
		<comments>http://www.wiseinn.com/index.php/others/seo/major-seo-popular-tools#comments</comments>
		<pubDate>Sun, 02 Oct 2011 09:06:35 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1982</guid>
		<description><![CDATA[&#160; Major SEO Popular Tools A good SEO will use certain tools in order to get a better search engine rank. Some of the tools will help guide the webmaster in repairing his site to make it more search engine friendly. Here are some of the best tools available for SEO. Same Page Checker : [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="color: rgb(66, 81, 99); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: rgb(191, 200, 215); ">
<div align="justify">
<h1 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: rgb(82, 105, 132); color: rgb(189, 203, 214); text-indent: 5px; ">Major SEO Popular Tools</h1>
<p>A good SEO will use certain tools in order to get a better search engine rank. Some of the tools will help guide the webmaster in repairing his site to make it more search engine friendly. Here are some of the best tools available for SEO.</p>
<p>Same Page Checker : When the spiders roll onto your web site they are checking to make sure that your content is all original. If the spider finds out that there are duplicate pages then the site will be penalized. With so many site son the internet it is going to be possible that there may be content similar to what you have , so in order to change that this tool lets you find out what exact percentage of similarities to other pages . This will help you correct the similarities making the content more original.</p>
<p>Search Engine Spider Simulator: What this tool does is it allows you to see a mock search engine and it shows the content of your site . It allows the webmaster to see the hyperlinks that will be searched by the spider. It gives the webmaster an idea of how the spiders work and by allowing you to see this it really gives you a heads up on fixing your site to get a better search engine rank.</p>
<p>Backlink Anchor Text Analysis : It is great that you have backlinks on your site but it really boils down to the quality of the backlinks . It is the quality that the search engines look for. If you have 10 backlinks on your site and 8 of them lead to nowhere then you are not going to get a good ranking. That is what this tool does, it rates your backlinks and lets you know if they are good enough to increase your search engine ranking.</p>
<p>Backlink Builder : What this SEO tool does is actually helps you to build quality backlinks. If after you use the Backlink Anchor Text Analysis tool and it determines that your links are not good enough then this tool can help you improve your links . It will searches your sites that you are using key phrases for. It will give instructions like add link or add site.</p>
<p>Keyword Density Checker : Search Engines do not like sites that are stuffed with keywords. So what this tool does is it checks your site and it will give you a percentage of the amount of times the keywords are used on your pages. This checker will crawl the specific URL you wish and it will remove the text that a search engine would remove and it also takes out common stop words and review the keyword density.</p>
<p>Domain Stats Tool: This tool will in fact help you get the stats of your competitors domains. If you have a site about dogs, it will give you the stats of other domains about dogs. The stats provided are the Yahoo WebRank, Pages that are indexed by other search engines, Backlink counts and Alexa Traffic Rank.</p>
<p>Keyword Playground: This tool is used to put in key phrases in the Search Engines in order to get certain information. It is critical that you target your optimization for such keywords. This tool will help you recognize key phrases and then send you a report on how many times it is searched.</p>
<p>Alexa Ranking Tool: Alexa is a web site that shows you all the stats from any website that you can think of. From current traffic to traffic from 6 months ago. Click Here for&nbsp;<a href="http://www.yourmaindomain.com/index.asp"><strong>SEO Tools</strong></a></p>
</div>
<p>&nbsp;</p>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/others/seo/major-seo-popular-tools/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is Search Engine?</title>
		<link>http://www.wiseinn.com/index.php/others/seo/what-is-search-engine</link>
		<comments>http://www.wiseinn.com/index.php/others/seo/what-is-search-engine#comments</comments>
		<pubDate>Sun, 02 Oct 2011 09:05:46 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1980</guid>
		<description><![CDATA[    What is Search Engine? A search engine is a information database system that helps users find websites they are looking for on the web. As a user you can go to one of many search engines on the web, for this discussion we will use Google, type in what you are searching for [...]]]></description>
			<content:encoded><![CDATA[ 
<div><span class="Apple-style-span" style="color: #425163; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: #bfc8d7;"> </span></div>
<div><span class="Apple-style-span" style="color: #425163; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: #bfc8d7;"></span></div>
<span class="Apple-style-span" style="color: #425163; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: #bfc8d7;">
<h1 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #526984; color: #bdcbd6; text-indent: 5px;"><strong>What is Search Engine?</strong></h1>
A search engine is a information database system that helps users find websites they are looking for on the web. As a user you can go to one of many search engines on the web, for this discussion we will use Google, type in what you are searching for in the search box and hit enter and Google will provide a list of all results that meet your needs. Some sites will be relevant and others won’t be. You could get as many a million search results for one topic. When using the search engine you don’t have to have a specific thing you are looking for in order to get results. For example, let’s say you want information dogs, but you don’t have anything specific yet you want to see. Type in the word dog and the search engine will back millions of results all pertaining to the word dog. It is up to you to either narrow your search or simply wade through the millions of sites pertaining to dogs.

The very first idea for searching the web was created in the 1990’s it was called Archie which was the word archive without the v. The program’s purpose was to download all of the files stored on the internet through FTP which is File Transfer Protocol. As Archie was being used to index computer files another program called Gopher was set up in 1991. Most of the files on the web were text files, Gopher’s sites became sites after the discovery of the World Wide Web. Over time tow other programs became available, one was called the Veronica which really meant Very Easy Rodent Oriented Net wide Index to Computerized Archives and the Jughead which stood for Jonzy’s Universal Gopher hierarchy Excavation And Display.

These programs were used as tools to get menu information from many different Gopher servers. The very first search engine was called Wandex which is no longer used, it was developed in 1993. The other search engine that was created in 1993 is called the Aliweb and it is still used today as a search engine. As the web become more prominent more and more search engines appeared and competed for traffic. It wasn’t until Google came on the scene in 1998 when the search engine craze went into overdrive. Google, Yahoo and MSN are the top three search engines on the World Wide Web today.

In 2001, Google began it’s ascent into being the most popular search engine. The popularity was mainly caused by how Google indexed their sites. They used link popularity as well as a PageRank system. Some of the problems facing search engines are that the web is growing more and more everyday, thousands and thousand of sites are popping up everyday. Search engines are not as fast they used to be when it comes to indexing the sites because of the quantity of sites.

Another problem facing search engines is that some of the search engines are having problems with relevancy. They have a hard time getting the information the users requested. Many times search engines don’t rank their sites by the subject matter but how well a site is done. There are even some search engines that rank their sites by how much money the matching site is willing to pay. A problem for site crawlers that search engines sent out can not look at the content on secure pages for technical reason or because they don’t want it index for privacy. As the web continues to grow, the use for search engines grow with it.

</span><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/others/seo/what-is-search-engine/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is SEO?</title>
		<link>http://www.wiseinn.com/index.php/others/seo/what-is-seo</link>
		<comments>http://www.wiseinn.com/index.php/others/seo/what-is-seo#comments</comments>
		<pubDate>Sun, 02 Oct 2011 09:04:26 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1978</guid>
		<description><![CDATA[&#160; What is SEO? SEO stands for Search Engine Optimization, it is the method of increasing the amount of quality and the amount of traffic that goes to a web site via the search engines like Google or Yahoo rather than natural traffic results. The way a search engine works is that when you build [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="color: rgb(66, 81, 99); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; background-color: rgb(191, 200, 215); ">
<div align="justify">
<h1 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: rgb(82, 105, 132); color: rgb(189, 203, 214); text-indent: 5px; "><strong>What is SEO?</strong></h1>
<p>SEO stands for Search Engine Optimization, it is the method of increasing the amount of quality and the amount of traffic that goes to a web site via the search engines like Google or Yahoo rather than natural traffic results. The way a search engine works is that when you build a site the search engine will send out a robot to scan your site and depending on the content whether it is original or not and the subject matter of the site the robot will report back to the search engine and the search engine will rank the site.</p>
</div>
<p align="justify">Of course in this case you want your site to be ranked low. Search engines list the sites starting from the number one. Through the process of search engine optimization you can improve your ranking if you are not happy with where the search engine places you. As a webmaster you can target your SEO through other avenues such as local searches, image searching and very specific vertical searches.</p>
<p align="justify">The webmaster may want to use algorithms as a marketing strategy. An algorithm is a recording methods used for solving specific math problems. So a webmaster can use an algorithm and try to figure out what people are searching for and how they are searching for it. A webmaster may wish to take a look at their own site and see what they can do to improve the SEO so they could get a better place in the search engines.</p>
<p align="justify">There are two types of SEO&rsquo;s the White hat and the Black hat, it is almost the proverbial good in the white vs. evil in the black. Search engines are more accepting of white hat than black but a good black hat goes undetected. Every couple a weeks a spider or robot will crawl your site and either raise your page ranking or lower it. If the spider reveals a black hat then they you may go from a number 100 in the search engine to a 125. The same works with white hat, if you raise your traffic and improve your site then the search engine will reward you with a lower number.</p>
<p align="justify">There are three main search engines, Google, Yahoo and Microsoft. Each search engine looks at different factors before determining where they are going to place you in the search engine. When the spiders come they do not look at every single page you have on your website. They do not index all the pages. When a site has pages that they do not want the search engines to see because it may affect their ranking they tell the spider not to look at certain files or certain directories through a standard robot file. A spider may keep a copy of the file and it could end up crawling the pages the webmaster did not want looked at.</p>
<p align="justify">The webmaster generally prevents the spiders from looking at pages with such things as shopping carts, login pages and other user specific content which may be search results that came from an internal search. Just this past March, Google sent a message to webmasters that they should not index internal searches because their search engines do consider them spam.</p>
<p align="justify">Some webmasters do the SEO work themselves but others may hire someone to it for them because no matter how hard they look at their site they cannot see why they are not getting a better ranking. These outside SEO&rsquo;s could provide a fresh pair of eyes and instruct the webmaster on what he needs to change his site, it could be a matter of adding better and more original content or it could be instructing the webmaster to make the site more user friendly.</p>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/others/seo/what-is-seo/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML Configuration files in SQL Server Integration Services</title>
		<link>http://www.wiseinn.com/index.php/database-articles/ssis/xml-configuration-files-in-sql-server-integration-services</link>
		<comments>http://www.wiseinn.com/index.php/database-articles/ssis/xml-configuration-files-in-sql-server-integration-services#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:35:15 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1973</guid>
		<description><![CDATA[&#160;by&#160;Robert Sheldon &#160; Package configuration files are a great way of providing the values of SSIS package properties so&#160;that packages&#160;can be used in a far more versatile way. They&#160;make the&#160;deployment of SSIS packages easier and can provide parameters that are based on the server configuration, or which change for each runtime. They&#8217;re easy to understand, [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="color: rgb(102, 102, 102); font-family: arial; font-size: medium; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-size: 13px; font-style: italic; line-height: 18px; ">by&nbsp;<a id="ctl00_MainContent_lnkAuthor" rel="author" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); ">Robert Sheldon</a></span>
<div class="article" style="color: rgb(51, 51, 51); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-size: 13px; line-height: 1.4; ">
<div class="clear" style="clear: both; ">&nbsp;</div>
<div id="pretty">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 80px; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">Package configuration files are a great way of providing the values of SSIS package properties so&nbsp;that packages&nbsp;can be used in a far more versatile way. They&nbsp;make the&nbsp;deployment of SSIS packages easier and can provide parameters that are based on the server configuration, or which change for each runtime. They&#8217;re easy to understand, especially when explained by Rob Sheldon.&nbsp;</p>
<p class="start" style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">When you develop a SQL Server Integration Services (SSIS) package, you can add package configurations in order to provide property values to the package at runtime. A package configuration is a defined property/value pair that can be modified without updating the package itself. Package configurations are useful when you want to deploy packages to multiple servers, when you move your packages from a development to production environment, or in any situation in which you want to provide property values to a package at runtime.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">SSIS provides several methods for storing package configurations. One of the most flexible of those methods is the XML configuration file. The file lets you store one or more package configurations that can be used by one or more packages. The easiest way to create an XML configuration file is to use the Package Configuration wizard after you&rsquo;ve set up your package. The wizard walks you through the steps necessary to create the file and lets you choose which property values you want to include in that file.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">In this article, I walk you through the steps necessary to create an XML configuration file. To demonstrate these steps, I first used the following Transact-SQL code to create the People table in the AdventureWorks2008R2 database:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; font-size: 11px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><span style="color: blue; ">USE</span>&nbsp;AdventureWorks2008R2<br />
<span style="color: blue; ">GO</span><br />
<br />
<span style="color: blue; ">IF</span>&nbsp;<span style="color: fuchsia; ">OBJECT_ID</span><span style="color: gray; ">(</span><span style="color: red; ">&#8216;dbo.People&#8217;</span><span style="color: gray; ">) IS NOT NULL</span><br />
<span style="color: blue; ">DROP TABLE</span>&nbsp;dbo.People<br />
<span style="color: blue; ">GO</span><br />
<br />
<span style="color: blue; ">SELECT TOP</span>&nbsp;1&nbsp;<span style="color: gray; ">*</span>&nbsp;<br />
<span style="color: blue; ">INTO</span>&nbsp;dbo.People<br />
<span style="color: blue; ">FROM</span>.Person</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Notice that I inserted only one row. I simply wanted to create the table and use the simplest method for doing so. The table will be truncated when you run the package, so it doesn&rsquo;t matter how many rows you insert into the table.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">After I created the People table, I created an SSIS project in SQL Server Business Intelligence Development Studio (BIDS) and renamed the default package LoadPersonData.</p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">You can download the SSIS package from the speech bubble at the top of the article.</p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">I then added two OLE DB connection managers, which each point to the AdventureWorks2008R2 database on the same instance of SQL Server. (Normally, they would point to two different instances, but for testing purposes, this is fine.) The first connection manager is named Server A. The second one is named Server B.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">After I added the connection managers, I defined a string variable named ConnectMngr and set its default value to &ldquo;Server A.&rdquo; The variable will be used in the control flow to indicate which connection manager to use. I then added an Execute SQL task and two Data Flow tasks to the control flow, as shown in Figure 1.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><img alt="The control flow in the LoadPersonData SSIS package" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image001.png" /></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 1: The control flow in the LoadPersonData SSIS package</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The Execute SQL task truncates the People table. The precedence constraints that connect to the Data Flow tasks are each configured to evaluate to an expression. For example, Figure 2 shows how I configured the precedence constraint that connects to the Server A Data Flow task. Notice that the expression specifies that the ConnectMngr variable must equal &ldquo;Server A&rdquo; in order to evaluate to True.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><img alt="Configuring the precedence constraint " src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image003.png" /></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 2: Configuring the precedence constraint to evaluate to an expression</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">I configured the second precedence constraint just like the first one, except that the expression specifies &ldquo;Server B&rdquo; as the variable value.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Next I configured each Data Flow task with an OLE DB source and an OLE DB destination. The sources and destination use their respective connection managers. For example, the Server A data flow uses the Server A connection manager. Figure 3 shows the Server A data flow components. Each data flow retrieves data from the Person table in the AdventureWorks2008R2 database and inserts that data in the People table.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><img alt="Configuring the data flow for the Server A connection manager" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image005.png" /></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 3: Configuring the data flow for the Server A connection manager</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">That&rsquo;s all there is to setting up your SSIS package. Although this is a very simple package, it&rsquo;s all we need to demonstrate how to implement XML configuration files. (Actually, we don&rsquo;t even need that much.) If you don&rsquo;t want to create this package, and instead want to use a package you&rsquo;ve already created, you should have no trouble applying the steps in the rest of the article to your situation.</p>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">Setting Up Your XML Configuration File</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">After you&rsquo;ve set up your package, the first step in setting up the XML configuration file is to enable package configurations. To do so, click the&nbsp;<strong>Package Configurations</strong>&nbsp;option on the&nbsp;<strong>SSIS</strong>&nbsp;menu. This launches the Package Configuration Organizer, shown in Figure 4.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1345-image007.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="The Package Configuration Organizer in SSIS" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image007small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 4: The Package Configuration Organizer in SSIS</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">To enable package configurations on your package, select the&nbsp;<strong>Enable package configurations</strong>&nbsp;checkbox. You can then add your package configurations to the package. To do so, click&nbsp;<strong>Add</strong>&nbsp;to launch the Package Configuration wizard. When the wizard appears, click&nbsp;<strong>Next</strong>&nbsp;to skip the&nbsp;<strong>Welcome</strong>&nbsp;screen. The&nbsp;<strong>Select Configuration Type</strong>&nbsp;screen will appear, as shown in Figure 5.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1345-image009.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="The Select Configuration Type screen in the Package Configuration wizard" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image009small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 5: The Select Configuration Type screen in the Package Configuration wizard</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">From the&nbsp;<strong>Configuration type</strong>&nbsp;drop-down list, select<strong>&nbsp;XML configuration file</strong>. You can then choose to specify your configuration settings directly or specify a Windows environment variable that stores the path and file names for the configuration file. For this example, I selected the&nbsp;<strong>Specify configuration settings directly</strong>&nbsp;option and specified the following path and file name: C:\Projects\SsisConfigFiles\LoadPersonData.dtsConfig. The main thing to notice is that the file should use the extension dtsConfig.</p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><strong>NOTE</strong>: If you specify an XML file that already exists, you&rsquo;ll be prompted whether to use that file or whether to overwrite the file&rsquo;s existing settings and use the package&rsquo;s current settings. If you use the file&rsquo;s settings, you&rsquo;ll skip the next screen, otherwise, the wizard will proceed as if the file had not existed. Also, if you choose to use an environment variable to store the path and file names, the wizard will not create a configuration file and will again skip the next screen. Even if you use an environment variable, you might want to create the file first and then select the environment variable option afterwards.</p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The next screen in the wizard is&nbsp;<strong>Select Properties to Export.</strong>&nbsp;As the name implies, this is where you select the properties for which you want package configurations. In this case, I selected the&nbsp;<strong>Value</strong>&nbsp;property for the ConnectMngr variable and the&nbsp;<strong>ServerName</strong>&nbsp;property for each of the two connections managers, as shown in Figure 6.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1345-image011.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="Selecting properties in the Package Configuration wizard" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image011small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 6: Selecting properties in the Package Configuration wizard</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Because I chose three properties, three package configurations will be created in the XML file. You can choose as many properties as you want to add to your file.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">On the next screen of the Package Configuration wizard, you provide a name for the configuration and review the settings (shown in Figure 7).</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><img alt="Completing the Wizard screen in the Package Configuration wizard" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image014.jpg" /></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 7: The Completing the Wizard screen in the Package Configuration wizard</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">If you&rsquo;re satisfied with the settings, click&nbsp;<strong>Finish</strong>. The wizard will automatically generate the XML configuration file and add the properties that you&rsquo;ve specified. The file will also be listed in the Package Configuration Organizer, as shown in Figure 8.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><img alt="The XML package configuration as it&rsquo;s listed in the Package Configuration Organizer" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image015small.png" /></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 8: The XML package configuration as it&rsquo;s listed in the Package Configuration Organizer</p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><strong>NOTE:</strong>&nbsp;When you add an XML configuration file, no values are displayed in the Target Object and Target Property columns of the Package Configuration Organizer. This is because XML configuration files support multiple package configurations.</p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">You should also verify whether the XML package configuration file has been created in the specified location. For this example, I added the file to the C:\Projects\SsisConfigFiles\ folder. The file is automatically saved with the dtsConfig extension. If you open the file in a text editor or browser, you should see the XML necessary for a configuration file. Figure 9 shows the LoadPersonData.dtsConfig file as it appears in Internet Explorer.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1345-image017.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="The XML in the LoadPersonData.dtsConfig file" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image017small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 9: The XML in the LoadPersonData.dtsConfig file</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">As Figure 9 shows, the XML configuration file includes the &lt;DTSConfigurationHeading&gt; element. The element contains the attributes and their values that define when, who, and how the file was generated. The file also includes one &lt;Configuration&gt; element for each package configuration. Each &lt;Configuration&gt; element includes the attributes and their values necessary to determine which property is being referenced. Within each &lt;Configuration&gt; element is a nested &lt;ConfiguredValue&gt; element, which provides the property&rsquo;s actual value.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Notice that the property values are the same as that of the package itself. When you first set up an XML configuration file, the current package value is used for each property. You can, of course, change those values, as I demonstrate later in the article.</p>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">Running Your SSIS Package</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">After you&rsquo;ve created your XML configuration file, you&rsquo;re ready to run your package. You run the package as you would any other SSIS package. However, because package configurations have been enabled, the package will check for any settings that have been predefined.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">For the example I&rsquo;ve been demonstrating here, the package will run as if nothing has changed because, as stated above, the XML configuration file contains the same values as the properties initially defined on the package. That means the&nbsp;<strong>ConnectMngr</strong>&nbsp;variable will still have a value of &ldquo;Server A,&rdquo; and the connection managers will still point to the same SQL Server computer. Figure 10 shows the package after it ran without modifying the XML configuration file.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><img alt="Running the LoadPersonData package with the default settings" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image019.png" /></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 10: Running the LoadPersonData package with the default settings</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">As you would expect, the Server A data flow ran, but not the Server B data flow. However, the advantage to using XML configuration files is that you can modify property settings without modifying the package itself. When the package runs, it checks the configuration file. If the file exists, it uses the values form the listed properties. That means if I change the property values in the file, the package will use those new values when it runs.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">For instance, if I change the value of the&nbsp;<strong>ConnectMngr</strong>&nbsp;variable from &ldquo;Server A&rdquo; to &ldquo;Server B,&rdquo; the package will use the value. As a result, the precedence constraint that connects to the Server A Data Flow task will evaluate to False, and the precedence constraint that connects to the Server B Data Flow task will evaluate to True, and the Server B data flow will run. Figure 11 shows what happens if I change the variable&rsquo;s value in the XML configuration file to &ldquo;Server B.&rdquo;</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><img alt="Running the Server B Data Flow task in the LoadPersonData SSIS package" src="http://www.simple-talk.com/iwritefor/articlefiles/1345-image021.png" /></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 11: Running the Server B Data Flow task in the LoadPersonData SSIS package</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">As you would expect, the Server B Data Flow task ran, but not the Server A Data Flow task. If I had changed the values of the ServerName properties for the connection managers, my source and destination servers would also have been different.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Clearly, XML configuration files offer a great deal of flexibility for supplying property values to your packages. They are particularly handy when deploying your packages to different environments. Server and instance names can be easily changed, as can any other value. If you hard-code the path and file name of the XML configuration file into the package, as I&rsquo;ve done in this example, then you must modify the package if that file location or name changes. You can get around this by using a Windows environment variable, but that&rsquo;s not always a practical solution. In addition, you can override the configuration path and file names by using the /CONFIGURATION option with the DTExec utility.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Whatever approach you take, you&rsquo;ll find XML configuration files to be a useful tool that can help streamline your development and deployment efforts. They&rsquo;re easy to set up and maintain, and well worth the time it takes to learn how to use them and how to implement them into your solutions.</p>
</div>
<br />
<br />
This article has been viewed 113 times.</div>
<div class="authorpanel" style="margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(103, 92, 109); border-right-color: rgb(103, 92, 109); border-bottom-color: rgb(103, 92, 109); border-left-color: rgb(103, 92, 109); background-color: rgb(232, 228, 234); color: rgb(51, 51, 51); font-size: 12px; "><a id="ctl00_MainContent_Author1_lnkImage" title="Robert Sheldon" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); "><img id="ctl00_MainContent_Author1_imgAuthor" class="authorpicture" src="http://www.simple-talk.com/iwritefor/publishers/120.gif" alt="Robert Sheldon" align="left" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; " /></a>
<p style="margin-top: 7px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><strong>Author profile:</strong>&nbsp;<a id="ctl00_MainContent_Author1_lnkName" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); ">Robert Sheldon</a></p>
<p style="margin-top: 7px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">After being dropped 35 feet from a helicopter and spending the next year recovering, Robert Sheldon left the Colorado Rockies and emergency rescue work to pursue safer and less painful interests&mdash;thus his entry into the world of technology. He is now a technical consultant and the author of numerous books, articles, and training material related to Microsoft Windows, various relational database management systems, and business intelligence design and implementation. He has also written news stories, feature articles, restaurant reviews, legal summaries, and the novel &#8216;Dancing the River Lightly&#8217;. You can find more information at http://www.rhsheldon.com.</p>
</div>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/database-articles/ssis/xml-configuration-files-in-sql-server-integration-services/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding the Script Task to Your SSIS Packages</title>
		<link>http://www.wiseinn.com/index.php/database-articles/ssis/adding-the-script-task-to-your-ssis-packages</link>
		<comments>http://www.wiseinn.com/index.php/database-articles/ssis/adding-the-script-task-to-your-ssis-packages#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:30:36 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SSIS]]></category>
		<category><![CDATA[SSIS Packages]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1970</guid>
		<description><![CDATA[&#160;by&#160;Robert Sheldon &#160; Script tasks are a great way of extending SSIS functionality, when none of the built-in&#160;components&#160;are quite right for the task you need to perform. But how to go about creating a script task? No worries, once again Robert Sheldon is on hand to provide easy instructions on how to do it. One [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="color: rgb(102, 102, 102); font-family: arial; font-size: medium; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-size: 13px; font-style: italic; line-height: 18px; ">by&nbsp;<a id="ctl00_MainContent_lnkAuthor" rel="author" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); ">Robert Sheldon</a></span>
<div class="article" style="color: rgb(51, 51, 51); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-size: 13px; line-height: 1.4; ">
<div class="clear" style="clear: both; ">&nbsp;</div>
<div id="pretty">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 80px; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">Script tasks are a great way of extending SSIS functionality, when none of the built-in&nbsp;components&nbsp;are quite right for the task you need to perform. But how to go about creating a script task? No worries, once again Robert Sheldon is on hand to provide easy instructions on how to do it.</p>
<p class="start" style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">One of the most effective ways to extend your SQL Server Integration Services (SSIS) control flow is to use a<strong>Script</strong>&nbsp;task to write custom code that perform tasks you cannot perform with the built-in components. For example, you can use the&nbsp;<strong>Script</strong>&nbsp;task to access Active Directory information or to create package-specific performance counters. You can also use the&nbsp;<strong>Script</strong>&nbsp;task to combine functions that might normally require multiple tasks and data flow components.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">In this article, I demonstrate how to implement a&nbsp;<strong>Script</strong>&nbsp;task into the control flow of a basic SSIS package. The purpose of the package is to retrieve data from a comma-separated values (CSV) file, insert the data into a SQL Server table (though no data is actually loaded), and then delete the file. The package includes a&nbsp;<strong>Script</strong>&nbsp;task that will first determine if the file has been updated since the last data load and, if so, whether the file currently contains data. You can download the SSIS package file, along with the two data files (one with data, and one without) from the speech-bubble at the head of the article. You&#8217;ll have to rename the data file that you use to PersonData.CSV.</p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 0in; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><strong>NOTE</strong>: The&nbsp;<strong>Script</strong>&nbsp;task is different from the&nbsp;<strong>Script</strong>&nbsp;component. The&nbsp;<strong>Script</strong>&nbsp;component can be used as a source, transformation, or destination to enhance the data flow, but it cannot be used in the control flow, just like the&nbsp;<strong>Script</strong>&nbsp;task is not available to the data flow. However, many of the basic concepts I cover in this article apply to the&nbsp;<strong>Script</strong>&nbsp;component.</p>
</div>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">Setting Up Your SSIS Package</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Before adding the&nbsp;<strong>Script</strong>&nbsp;task to your SSIS package, you should add and configure any components that are necessary to support the task, such as variables, connections managers, and other tasks. For the example in this article, however, I created a CSV file named PersonData.csv before adding any components to the package. To make it simpler for you to create the file, I&rsquo;m including the bcp command I used to generate the file on my system:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p class="auto-style1" style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">bcp &quot;SELECT TOP 100 * FROM AdventureWorks2008R2.Person.Person ORDER BY BusinessEntityID&quot; queryout C:\DataFiles\PersonData.csv -c -t, -S localhost\SqlSrv2008R2 &ndash;T</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Notice that the command retrieves Person data from the AdventureWorks2008R2 database and adds that data to the C:\DataFiles\PersonData.csv file. I also created a second bcp command to create an empty file with the same name. I did this in order to fully test the SSIS package. In the SELECT statement in the second command, I include a WHERE clause that references a nonexistent BusinessEntityID value:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p class="auto-style1" style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">bcp &quot;SELECT * FROM AdventureWorks2008R2.Person.Person WHERE BusinessEntityID = 123456789&quot; queryout C:\DataFiles\PersonData.csv -c -t, -S localhost\SqlSrv2008R2 &ndash;T</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Because I&rsquo;m referencing a nonexistent BusinessEntityID value, the command creates an empty CSV file. You can use either file to test your SSIS package, should you decide to try the example I&rsquo;m demonstrating in this article.</p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 0in; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><strong>NOTE</strong>: I tested the SSIS package against both files. However, because the files share the same name, I had to create them one at a time, deleting the original, as necessary, after I ran the SSIS package.</p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The&nbsp;<strong>Script</strong>&nbsp;task that I&rsquo;ll be demonstrating will reference two SSIS user-defined variables, so after I created the CSV file, I added the following two variables to my package:</p>
<ul style="margin-top: 0px; ">
    <li style="text-align: justify; margin-top: 0px; font-family: Arial, Helvetica, sans-serif; margin-bottom: 3px; margin-left: 20px; font-size: 12px; "><strong>IsEmpty:</strong>&nbsp;A Boolean variable with a package-level scope. The variable will be used by the&nbsp;<strong>Script</strong>&nbsp;task to specify whether the source CSV file contains data. I&rsquo;ve set the initial value to False, but the&nbsp;<strong>Script</strong>&nbsp;task will set the final value, so you can set the initial value to either True or False.</li>
    <li style="text-align: justify; margin-top: 0px; font-family: Arial, Helvetica, sans-serif; margin-bottom: 3px; margin-left: 20px; font-size: 12px; "><strong>LastUpdate:</strong>&nbsp;A DateTime variable with a package-level scope. I&rsquo;ve set the value as an arbitrary date that precedes the date that I created the CSV files. In theory, the&nbsp;<strong>LastUpdate</strong>&nbsp;variable stores the timestamp of the last time the package ran and updated the database. In reality, this date would probably come from a table or some other system that logged the updates. For this article, however, it serves our purposes to set a hard-coded date.</li>
</ul>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">My next step was to create a&nbsp;<strong>Flat File</strong>&nbsp;connection manager named&nbsp;<strong>PersonData</strong>. The connection manager connects to the C:\DataFiles\PersonData.csv file. Other than naming the connection manager and providing a description, I retained the default settings for its other options.</p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 0in; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><strong>NOTE</strong>: This article assumes that you know how to run bcp commands as well as add and configure SSIS components, such as variables, connection managers, and tasks. If you&rsquo;re not familiar how to use bcp or work with these components, you should first review the relevant topics in SQL Server Books Online or in another source.</p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The two variables and&nbsp;<strong>Flat File</strong>&nbsp;connection manager are the only SSIS components necessary to support the&nbsp;<strong>Script</strong>task that I&rsquo;m going to demonstrate. So let&rsquo;s look at how to add and configure that task.</p>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">Adding the Script Task to Your Package</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">After you add the&nbsp;<strong>Script</strong>&nbsp;task to your SSIS package, you can configure it by opening the&nbsp;<strong>Script Task Editor</strong>. On the editor&rsquo;s&nbsp;<strong>General</strong>&nbsp;page, you should provide a name and description for the task. (I named the task&nbsp;<strong>Check file status</strong>.) Next, go to the editor&rsquo;s&nbsp;<strong>Script</strong>&nbsp;page to configure the script-related properties, as shown in Figure 1.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1328-image001.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="Script page of the Script Task Editor" src="http://www.simple-talk.com/iwritefor/articlefiles/1328-image001small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 1: Script page of the Script Task Editor</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The first property that you need to set is&nbsp;<strong>ScriptLanguage</strong>. You can create your scripts in one of two languages: Visual Basic 2008 or Visual C# 2008. I used C# for the script that I created.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The next property on the&nbsp;<strong>Script</strong>&nbsp;page is&nbsp;<strong>EntryPoint</strong>. This is the method (specific to the selected script language) that the SSIS runtime calls as the entry point into your code. The Main method, in most cases, should work fine. However, if you choose another method, it must be in the ScriptMain class of the Visual Studio for Applications (VSTA) project.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The next two properties on the&nbsp;<strong>Script</strong>&nbsp;page are&nbsp;<strong>ReadOnlyVariables</strong>&nbsp;and&nbsp;<strong>ReadWriteVariables</strong>. As the names imply, you enter the name of any SSIS variables you want to use in your script. (Separate the names with commas for multiple variables of either type.) For instance, I added the&nbsp;<strong>LastUpdate</strong>&nbsp;variable to the&nbsp;<strong>ReadOnlyVariables</strong>&nbsp;property and the&nbsp;<strong>IsEmpty</strong>&nbsp;variable to the&nbsp;<strong>ReadWriteVariables</strong>&nbsp;property. As a result, my C# script will be able to retrieve the date from the&nbsp;<strong>LastUpdate</strong>&nbsp;variable and set the file status in the&nbsp;<strong>IsEmpty</strong>&nbsp;variable.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">That&rsquo;s all there is to configuring the&nbsp;<strong>Script</strong>&nbsp;task properties in preparation for creating the script itself, so once you&rsquo;ve configured the properties, click the&nbsp;<strong>Edit Script</strong>&nbsp;button on the editor&rsquo;s&nbsp;<strong>Script</strong>&nbsp;page to open the VSTA integrated development environment (IDE) window, shown in Figure 2. All script modifications are made in the VSTA development environment.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1328-image003.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="Default C# code in the VSTA IDE window" src="http://www.simple-talk.com/iwritefor/articlefiles/1328-image003small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 2: Default C# code in the VSTA IDE window</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">As Figure 2 shows, when you first open the VSTA window, you&rsquo;ll see the default C# script, which includes the language necessary to work with the Main method of the ScriptMain class. Because Figure 2 shows only part of the script, I&rsquo;m included the entire default code here for your convenience:</p>
<div class="smalllisting" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">/*</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;</span>Microsoft SQL Server Integration Services Script Task</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;</span>Write scripts using Microsoft Visual C# 2008.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;</span>The ScriptMain is the entry point class of the script.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">*/</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;System;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;System.Data;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;Microsoft.SqlServer.Dts.Runtime;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;System.Windows.Forms;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">namespace</span><span lang="EN-US">&nbsp;ST_96fb03801a81438dbb2752f91e76b1d5.csproj</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>[System.AddIn.<span style="color: rgb(43, 145, 175); ">AddIn</span>(<span style="color: rgb(163, 21, 21); ">&quot;ScriptMain&quot;</span>, Version =&nbsp;<span style="color: rgb(163, 21, 21); ">&quot;1.0&quot;</span>, Publisher =&nbsp;<span style="color: rgb(163, 21, 21); ">&quot;&quot;</span>, Description =&nbsp;<span style="color: rgb(163, 21, 21); ">&quot;&quot;</span>)]</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">public</span>&nbsp;<span style="color: blue; ">partial</span>&nbsp;<span style="color: blue; ">class</span>&nbsp;<span style="color: rgb(43, 145, 175); ">ScriptMain</span>&nbsp;: Microsoft.SqlServer.Dts.Tasks.ScriptTask.<span style="color: rgb(43, 145, 175); ">VSTARTScriptObjectModelBase</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>#region</span><span lang="EN-US">&nbsp;VSTA generated code</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">enum</span>&nbsp;<span style="color: rgb(43, 145, 175); ">ScriptResults</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Success = Microsoft.SqlServer.Dts.Runtime.<span style="color: rgb(43, 145, 175); ">DTSExecResult</span>.Success,</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Failure = Microsoft.SqlServer.Dts.Runtime.<span style="color: rgb(43, 145, 175); ">DTSExecResult</span>.Failure</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>};</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>#endregion</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">/*</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>The execution engine calls this method when the task executes.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>To access the object model, use the Dts property. Connections, variables, events,</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>and logging features are available as members of the Dts property as shown in the following examples.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>To reference a variable, call Dts.Variables[&quot;MyCaseSensitiveVariableName&quot;].Value;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>To post a log entry, call Dts.Log(&quot;This is my log text&quot;, 999, null);</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>To fire an event, call Dts.Events.FireInformation(99, &quot;test&quot;, &quot;hit the help message&quot;, &quot;&quot;, 0, true);</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>To use the connections collection use something like the following:</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>ConnectionManager cm = Dts.Connections.Add(&quot;OLEDB&quot;);</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>cm.ConnectionString = &quot;Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;&quot;;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>To open Help, press F1.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>*/</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">public</span>&nbsp;<span style="color: blue; ">void</span>&nbsp;Main()</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// TODO: Add your code here</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.TaskResult = (<span style="color: blue; ">int</span>)<span style="color: rgb(43, 145, 175); ">ScriptResults</span>.Success;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="line-height: 18px; ">}</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">For the most part, you need to be concerned only with adding code to the Main method, specifically, to the section that is marked with the comment&nbsp;<span style="font-family: 'Courier New', Courier, monospace; color: green; ">// TODO: Add your code here</span>. (Comments are either preceded by double slashes for a single line or enclosed slashes and asterisks&mdash;/* and */&mdash;for multiple lines.) Usually, the only exception to where you enter code is at the beginning of the script, where you include the necessary&nbsp;<em>using</em>statements to define the relevant namespaces. For instance, the script includes the&nbsp;<span style="font-family: 'Courier New', Courier, monospace; color: blue; ">using</span>&nbsp;<span style="font-family: 'Courier New', Courier, monospace; ">System</span>; statement so we can access classes in the System namespace, like those that reference components such as events, interfaces, and data types.</p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 0in; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><strong>NOTE</strong>: A full explanation of how to use the C# language within a&nbsp;<strong>Script</strong>&nbsp;task is beyond the scope of this article. For specifics about the language, refer to a more complete resource, such as MSDN.</p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Other than the&nbsp;<em>using</em>&nbsp;statements and the Main method, you should, for the most part, leave the rest of the code alone, except for perhaps deleting comments. (Unless you&rsquo;re a C# pro&mdash;then have add it.) Now let&rsquo;s look how to modify the script to check the status of our flat file.</p>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">Writing Your C# Script</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The first step I often take when working the code in the&nbsp;<strong>Script</strong>&nbsp;task is to get rid of the comments. In this case, I removed the comments before the Main method. You can also delete the opening comments, but I left them in just to provide a few reminders about the environment in which we&rsquo;re working. So let&rsquo;s look at how I&rsquo;ve modified the script, and then I&rsquo;ll explain the changes I&rsquo;ve made. The following code shows how I&rsquo;ve updated the original script and expanded the Main method:</p>
<div class="smalllisting" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;</span>Microsoft SQL Server Integration Services Script Task</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;</span>Write scripts using Microsoft Visual C# 2008.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; "><span>&nbsp;&nbsp;&nbsp;</span>The ScriptMain is the entry point class of the script.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">*/</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;System;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;System.Data;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;Microsoft.SqlServer.Dts.Runtime;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;System.Windows.Forms;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">using</span><span lang="EN-US">&nbsp;System.IO;&nbsp;<span style="color: green; ">//added to support file access</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">namespace</span><span lang="EN-US">&nbsp;ST_5bd724e0deb3452e8646db6ec63913b0.csproj</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>[System.AddIn.<span style="color: rgb(43, 145, 175); ">AddIn</span>(<span style="color: rgb(163, 21, 21); ">&quot;ScriptMain&quot;</span>, Version =&nbsp;<span style="color: rgb(163, 21, 21); ">&quot;1.0&quot;</span>, Publisher =&nbsp;<span style="color: rgb(163, 21, 21); ">&quot;&quot;</span>, Description =&nbsp;<span style="color: rgb(163, 21, 21); ">&quot;&quot;</span>)]</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">public</span>&nbsp;<span style="color: blue; ">partial</span>&nbsp;<span style="color: blue; ">class</span>&nbsp;<span style="color: rgb(43, 145, 175); ">ScriptMain</span>&nbsp;: Microsoft.SqlServer.Dts.Tasks.ScriptTask.<span style="color: rgb(43, 145, 175); ">VSTARTScriptObjectModelBase</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>#region</span><span lang="EN-US">&nbsp;VSTA generated code</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">enum</span>&nbsp;<span style="color: rgb(43, 145, 175); ">ScriptResults</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Success = Microsoft.SqlServer.Dts.Runtime.<span style="color: rgb(43, 145, 175); ">DTSExecResult</span>.Success,</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Failure = Microsoft.SqlServer.Dts.Runtime.<span style="color: rgb(43, 145, 175); ">DTSExecResult</span>.Failure</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>};</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>#endregion</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">public</span>&nbsp;<span style="color: blue; ">void</span>&nbsp;Main()</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// Define C# variable to reference SSIS user variable.</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(43, 145, 175); ">DateTime</span>&nbsp;LastLoggedUpdate = (<span style="color: rgb(43, 145, 175); ">DateTime</span>)(Dts.Variables[<span style="color: rgb(163, 21, 21); ">&quot;LastUpdate&quot;</span>].Value);</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// Define variable for connection string.</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">string</span>&nbsp;PersonDataConnection = (<span style="color: blue; ">string</span>)(Dts.Connections[<span style="color: rgb(163, 21, 21); ">&quot;PersonData&quot;</span>].AcquireConnection(<span style="color: blue; ">null</span>)&nbsp;<span style="color: blue; ">as</span>&nbsp;<span style="color: rgb(43, 145, 175); ">String</span>);</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// Create file object based on file connection.</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(43, 145, 175); ">FileInfo</span>&nbsp;PersonDataFile =&nbsp;<span style="color: blue; ">new</span>&nbsp;<span style="color: rgb(43, 145, 175); ">FileInfo</span>(PersonDataConnection);</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// Retrieve properties from file object.</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(43, 145, 175); ">DateTime</span>&nbsp;LastModified = PersonDataFile.LastWriteTime;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">long</span>&nbsp;PersonFileSize = PersonDataFile.Length;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// If the file was modified since the last logged update,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// set IsEmpty variable and set the task result to Success.</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: green; ">// Otherwise, fail the task.</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">if</span>(LastModified &gt; LastLoggedUpdate)</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">if</span>(PersonFileSize &gt; 0)</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.Variables[<span style="color: rgb(163, 21, 21); ">&quot;IsEmpty&quot;</span>].Value =&nbsp;<span style="color: blue; ">false</span>;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">else</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.Variables[<span style="color: rgb(163, 21, 21); ">&quot;IsEmpty&quot;</span>].Value =&nbsp;<span style="color: blue; ">true</span>;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.TaskResult = (<span style="color: blue; ">int</span>)<span style="color: rgb(43, 145, 175); ">ScriptResults</span>.Success;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">else</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.TaskResult = (<span style="color: blue; ">int</span>)<span style="color: rgb(43, 145, 175); ">ScriptResults</span>.Failure;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 7pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">}</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Let&rsquo;s start with the&nbsp;<em>using</em>&nbsp;statements at the beginning of the script. You might have noticed that I added the&nbsp;<span style="font-family: 'Courier New', Courier, monospace; color: blue; ">using</span><span style="font-family: 'Courier New', Courier, monospace; ">System.IO</span>; statement. The System.IO namespace lets us access the language components we need in order to retrieve information about the flat file. I did not modify the script outside the Main method in any other way (except for deleting comments), so now let&rsquo;s look at that method.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The first item I added after the Main method declaration is a DateTime variable named&nbsp;<strong>LastLoggedUpdate</strong>:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">// Define C# variable to reference SSIS user variable.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: rgb(43, 145, 175); ">DateTime</span><span lang="EN-US">&nbsp;LastLoggedUpdate = (<span style="color: rgb(43, 145, 175); ">DateTime</span>)(Dts.Variables[<span style="color: rgb(163, 21, 21); ">&quot;LastUpdate&quot;</span>].Value);</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">I&rsquo;ve set the variable value to equal that of the SSIS&nbsp;<strong>LastUpdate</strong>&nbsp;variable that I defined on the package. To retrieve the value of the SSIS variable, I use the Dts object&rsquo;s&nbsp;<strong>Variables</strong>&nbsp;property, which returns a&nbsp;<strong>Variable</strong>&nbsp;object. I then specify the name of the variable, enclosed in double-quotes and brackets, and tag on the&nbsp;<strong>Value</strong>&nbsp;property (available through the&nbsp;<strong>Variable</strong>&nbsp;object). This lets me retrieve the variable&rsquo;s actual value. Note that I also cast the&nbsp;<strong>LastUpdate</strong>&nbsp;value to the DateTime data type by preceding the Dts variable construction by the name of the data type, just like I do when I declare the&nbsp;<strong>LastLoggedUpdate</strong>&nbsp;variable. I can now reference the&nbsp;<strong>LastLoggedUpdate</strong>&nbsp;variable within the Main method, and it will return the data currently stored the&nbsp;<strong>LastUpdate</strong>&nbsp;SSIS variable.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Next I declare a string variable named&nbsp;<strong>PersonDataConnection&nbsp;</strong>to hold the connection string I retrieve through the<strong>PersonData&nbsp;</strong>connection manager:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">// Define variable for connection string.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">string</span><span lang="EN-US">&nbsp;PersonDataConnection = (<span style="color: blue; ">string</span>)(Dts.Connections[<span style="color: rgb(163, 21, 21); ">&quot;PersonData&quot;</span>].AcquireConnection(<span style="color: blue; ">null</span>)&nbsp;<span style="color: blue; ">as</span>&nbsp;<span style="color: rgb(43, 145, 175); ">String</span>);</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Notice that my declaration once again begins with the data type, followed by the name of the variable. I then set the variable&rsquo;s value to equal the connection string. I retrieve the connection string by using the Dts object&rsquo;s<strong>Connections</strong>&nbsp;property. This is followed by the name of the connection manager, enclosed in double-quotes and brackets, and then by the&nbsp;<strong>AcquireConnection</strong>&nbsp;method. The method takes one argument&mdash;the handle to a transaction type. In this case, we can specify NULL , which indicates that the container supports transactions but is not going to participate. In other words, you don&rsquo;t need to worry about this. Just pass in NULL for this type of connection. Notice also that I&rsquo;m explicitly converting the connection object to a string to pass into the<strong>PersonDataConnection</strong>&nbsp;variable.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The next variable I declare is&nbsp;<strong>PersonDataFile</strong>, which is defined with type FileInfo:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">// Create file object based on file connection.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: rgb(43, 145, 175); ">FileInfo</span><span lang="EN-US">&nbsp;PersonDataFile =&nbsp;<span style="color: blue; ">new</span>&nbsp;<span style="color: rgb(43, 145, 175); ">FileInfo</span>(PersonDataConnection);</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">In this case, the variable&rsquo;s value is based on a new instance of the&nbsp;<strong>FileInfo</strong>&nbsp;class. Because the&nbsp;<strong>FileInfo</strong>&nbsp;constructor takes the&nbsp;<strong>PersonDataConnection</strong>&nbsp;variable as an argument, you can use the methods and properties available to the&nbsp;<strong>FileInfo</strong>&nbsp;class to access information about the PersonData.csv file. That means you can access those properties and methods through the&nbsp;<strong>PersonDataFile</strong>&nbsp;variable, which is what I do in the next two variable declarations:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">// Retrieve properties from file object.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: rgb(43, 145, 175); ">DateTime</span><span lang="EN-US">&nbsp;LastModified = PersonDataFile.LastWriteTime;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">long</span><span lang="EN-US">&nbsp;PersonFileSize = PersonDataFile.Length;</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">First, I declare a DateTime variable named&nbsp;<strong>LastModified</strong>&nbsp;and set its value to equal the value of the&nbsp;<strong>LastWriteTime</strong>property of the&nbsp;<strong>PersonDataFile</strong>&nbsp;variable, which is a FileInfo object. This will provide me with a timestamp of the last time the file was modified. I declare the second variable with the long data type and name the variable<strong>PersonFileSize</strong>. I then set the variable value to equal that of the file object&rsquo;s&nbsp;<strong>Length</strong>&nbsp;property.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">After I&rsquo;ve declared the necessary variables, I&rsquo;m ready to implement the logic needed to check the status of the PersonData.csv file. In the next section of code, I include two if&hellip;else statements, one embedded in the other:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">// If the file was modified since the last logged update,</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">// set IsEmpty variable and set the task result to Success.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: green; ">// Otherwise, fail the task.</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">if</span><span lang="EN-US">(LastModified &gt; LastLoggedUpdate)</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">if</span>(PersonFileSize &gt; 0)</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.Variables[<span style="color: rgb(163, 21, 21); ">&quot;IsEmpty&quot;</span>].Value =&nbsp;<span style="color: blue; ">false</span>;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue; ">else</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.Variables[<span style="color: rgb(163, 21, 21); ">&quot;IsEmpty&quot;</span>].Value =&nbsp;<span style="color: blue; ">true</span>;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.TaskResult = (<span style="color: blue; ">int</span>)<span style="color: rgb(43, 145, 175); ">ScriptResults</span>.Success;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">}</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">else</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">{</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Dts.TaskResult = (<span style="color: blue; ">int</span>)<span style="color: rgb(43, 145, 175); ">ScriptResults</span>.Failure;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US">}</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Let&rsquo;s start by looking at the outer&nbsp;<strong>if&hellip;else</strong>&nbsp;construction. Essentially, what this is saying is, &ldquo;If the last modified date is more recent that the last time data was loaded into the database, run the script in the&nbsp;<strong>if&nbsp;</strong>section. Otherwise, skip to the end of the script and show the&nbsp;<strong>Script</strong>&nbsp;task as having failed.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The&nbsp;<strong>if</strong>&nbsp;statement begins by specifying the condition that determines whether to run the code in the if section or in the else section. If the condition evaluates to True&mdash;in this case, the&nbsp;<strong>LastModified</strong>&nbsp;date is more recent that the<strong>LastLoggedUpdate</strong>&nbsp;date&mdash;the code in the rest of the if section should run. If the condition does not evaluate to true, the code in the if section does not run and the code in the else section runs, which sets the Dts object&rsquo;s TaskResult property to Failure. (The TaskResult property tells the runtime whether the task succeeded or failed.)</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">The embedded&nbsp;<strong>if&hellip;else</strong>&nbsp;construction checks whether the value in the&nbsp;<strong>PersonFileSize</strong>&nbsp;variable is greater than 0, in other words, whether the file contains any data. If the file does contain data, the code in the&nbsp;<strong>if</strong>&nbsp;section runs, otherwise the code in the&nbsp;<strong>else</strong>&nbsp;section runs. As a result, if the file contains data, the SSIS&nbsp;<strong>IsEmpty</strong>&nbsp;variable is set to false. If the file contains no data, the variable is set to true. Notice that after the embedded&nbsp;<strong>if&hellip;else</strong>&nbsp;construction, I&rsquo;ve set the value of the&nbsp;<strong>TaskResult</strong>&nbsp;property to show that the task has successfully run.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">That&rsquo;s all there is to the script. Normally, you would also include code to handle exceptions, but what I&rsquo;ve shown you here should provide you with an overview of the script&rsquo;s basics elements. You can now close the VSTA window and then click&nbsp;<strong>OK</strong>&nbsp;to close the&nbsp;<strong>Script Task Editor</strong>. Be sure to save your changes.</p>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">Adding Other Tasks to Your Package</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">After I completed configuring the&nbsp;<strong>Script</strong>&nbsp;task and writing the C# script, I added a&nbsp;<strong>Data Flow</strong>&nbsp;task to the control flow. The data flow should, in theory, retrieve the data from the PersonData.csv file and insert it into a SQL Server database. However, for the purposes of this exercise, the<strong>&nbsp;Data Flow</strong>&nbsp;task serves only as a placeholder. It will still run like any other&nbsp;<strong>Data Flow</strong>&nbsp;task, but no data will actually be moved. Even so, you can still verify whether your control flow is set up correctly.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Next, I connected a precedence constraint from the&nbsp;<strong>Script</strong>&nbsp;task to the&nbsp;<strong>Data Flow</strong>&nbsp;task. I then added a&nbsp;<strong>File System</strong>task to the control flow and configured it to delete the PersonData.csv file. Next I connected a precedence constraint from the&nbsp;<strong>Script</strong>&nbsp;task to the&nbsp;<strong>File System</strong>&nbsp;task and one from the<strong>&nbsp;Data Flow</strong>&nbsp;task to the&nbsp;<strong>File System</strong>&nbsp;task. I then configured the two precedence constraints connecting to the&nbsp;<strong>File System</strong>&nbsp;task with the<strong>&nbsp;Logical OR</strong>&nbsp;option, which means that only one constraint must evaluate to True for the task to run. (By default, all constraints connected to a task must evaluate to True for the task to run.) Figure 3 shows what the control flow looked like after I added all the components.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1328-image006.jpg" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="Adding a Data Flow task and File System task to the control flow" src="http://www.simple-talk.com/iwritefor/articlefiles/1328-image006small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 3: Adding a Data Flow task and File System task to the control flow</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Notice how the precedence constraints connecting to the&nbsp;<strong>File System</strong>&nbsp;task are dotted lines. This indicates that the constraints have been configured with the&nbsp;<strong>Logical OR</strong>&nbsp;option. Also notice that an expression is associated with each of the precedence constraints leading out of the&nbsp;<strong>Script</strong>&nbsp;task (as indicated by the&nbsp;<em>fx</em>&nbsp;label). Both constraints are configured so that the tasks down the line will run only if the&nbsp;<strong>Script</strong>&nbsp;task runs successfully&nbsp;<em>and</em>&nbsp;the expression evaluates to True. I defined the following expression on the precedence constraint that connects to the&nbsp;<strong>Data Flow</strong>task:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="line-height: 22px; ">@[User::IsEmpty] == false</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">This means that the&nbsp;<strong>IsEmpty</strong>&nbsp;variable must be set to False in order for the expression to evaluate to True. The expression defined on the precedence constraint that leads from the&nbsp;<strong>Script</strong>&nbsp;task to the&nbsp;<strong>File System</strong>&nbsp;task is as follows:</p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="line-height: 22px; ">@[User::IsEmpty] == true</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">This means, of course, that the&nbsp;<strong>IsEmpty</strong>&nbsp;variable must be set to True for the expression to evaluate to True. And that about does it for setting up the SSIS package. The only other step I took was to add a breakpoint to the&nbsp;<strong>Script</strong>&nbsp;task, which I&rsquo;ll explain in the following section.</p>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">Running Your SSIS Package</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Before I ran the SSIS package, I added a breakpoint on the&nbsp;<strong>OnPostExecute</strong>&nbsp;event to the&nbsp;<strong>Script</strong>&nbsp;task. As a result, when I ran the package, it stopped running as it was about to complete the&nbsp;<strong>Script</strong>&nbsp;task. Figure 4 shows what the package looks like when it stopped running.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1328-image007.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="Using a breakpoint to view variable values" src="http://www.simple-talk.com/iwritefor/articlefiles/1328-image007small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 4: Using a breakpoint to view variable values</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">When the package stopped running, I added a watch (shown in the bottom pane in Figure 4) on each of the two variables I created early on. The watches show the variable values at the time the package reached the breakpoint. Notice that the&nbsp;<strong>IsEmpty</strong>&nbsp;variable is set to False. Had the PersonData.csv file contained no data, the variable would have been set to True.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Next, I resumed running the package until it executing all applicable tasks. As Figure 5 shows, every control flow task ran. That&rsquo;s because the&nbsp;<strong>IsEmpty</strong>&nbsp;variable evaluated to False and the&nbsp;<strong>Data Flow</strong>&nbsp;task ran and then the&nbsp;<strong>File System</strong>&nbsp;task ran.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1328-image009.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="Running the SSIS package when IsEmpty is false" src="http://www.simple-talk.com/iwritefor/articlefiles/1328-image009small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 5: Running the SSIS package when IsEmpty is false.</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">If the&nbsp;<strong>IsEmpty</strong>&nbsp;variable had evaluated to True, the&nbsp;<strong>Data Flow</strong>&nbsp;task would not have run, which is what happened when I added an empty file to the C:\DataFiles folder. This time around, only the&nbsp;<strong>Script</strong>&nbsp;task and&nbsp;<strong>File System</strong>&nbsp;task ran, as shown in Figure 6.</p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><a href="http://www.simple-talk.com/iwritefor/articlefiles/1328-image011.png" target="_blank" style="text-decoration: none; color: rgb(204, 102, 51); "><img alt="Running the SSIS package when IsEmpty is true" src="http://www.simple-talk.com/iwritefor/articlefiles/1328-image011small.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></a></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">Notice that the value of the&nbsp;<strong>IsEmpty</strong>&nbsp;variable shown in the Watch window is set to True. As a result, the file would have been deleted, but no attempts would have been made to load data into the database.</p>
<h2 style="font-family: 'Times New Roman', Times, serif; margin-left: 20px; font-size: 17px; ">And It Doesn&rsquo;t End There</h2>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; ">In the example above, the SSIS package performed in two different ways, depending on whether the file contained data. But there is a third scenario: the file was not updated since the last data load. If that happens, the&nbsp;<strong>Script</strong>&nbsp;task fails and the package stops running, which is what we&rsquo;d expect given the way the script is written in the&nbsp;<strong>Script</strong>&nbsp;task. Another thing that the example doesn&rsquo;t reflect is what would happen if the script threw an exception. Given that I&rsquo;ve included no exception handling, I would again expect the task to fail. What this points to is that the example I&rsquo;ve shown you here is only a simple script that contains relatively few elements. A script can be far more complex and take many more actions than what I&rsquo;ve demonstrated here. However, you should now at least have enough information to get started creating your own scripts and using the&nbsp;<strong>Script</strong>&nbsp;task to extend your control flow so you can perform the tasks that need to be performed.</p>
</div>
<br />
<br />
This article has been viewed 3718 times.</div>
<div class="authorpanel" style="margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(103, 92, 109); border-right-color: rgb(103, 92, 109); border-bottom-color: rgb(103, 92, 109); border-left-color: rgb(103, 92, 109); background-color: rgb(232, 228, 234); color: rgb(51, 51, 51); font-size: 12px; "><a id="ctl00_MainContent_Author1_lnkImage" title="Robert Sheldon" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); "><img id="ctl00_MainContent_Author1_imgAuthor" class="authorpicture" src="http://www.simple-talk.com/iwritefor/publishers/120.gif" alt="Robert Sheldon" align="left" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; " /></a>
<p style="margin-top: 7px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><strong>Author profile:</strong>&nbsp;<a id="ctl00_MainContent_Author1_lnkName" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); ">Robert Sheldon</a></p>
<p style="margin-top: 7px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">After being dropped 35 feet from a helicopter and spending the next year recovering, Robert Sheldon left the Colorado Rockies and emergency rescue work to pursue safer and less painful interests&mdash;thus his entry into the world of technology. He is now a technical consultant and the author of numerous books, articles, and training material related to Microsoft Windows, various relational database management systems, and business intelligence design and implementation. He has also written news stories, feature articles, restaurant reviews, legal summaries, and the novel &#8216;Dancing the River Lightly&#8217;.&nbsp;</p>
</div>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/database-articles/ssis/adding-the-script-task-to-your-ssis-packages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS Event Handlers Basics</title>
		<link>http://www.wiseinn.com/index.php/database-articles/ssis/ssis-event-handlers-basics</link>
		<comments>http://www.wiseinn.com/index.php/database-articles/ssis/ssis-event-handlers-basics#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:24:20 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1968</guid>
		<description><![CDATA[&#160;by&#160;Robert Sheldon &#160; SSIS event handlers are the simplest means of turning an SSIS script into a reliable system that is auditable, reacts appropriately to error conditions, reports progress and allows instrumentation&#160;and monitoring your SSIS packages.&#160;They are&#160;easy&#160;to implement,&#160;and provide a great deal of flexibility. Rob Sheldon once again provides the easy, clear introduction. Since the [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="color: rgb(102, 102, 102); font-family: arial; font-size: medium; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-size: 13px; font-style: italic; line-height: 18px; ">by&nbsp;<a id="ctl00_MainContent_lnkAuthor" rel="author" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); ">Robert Sheldon</a></span>
<div class="article" style="color: rgb(51, 51, 51); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-size: 13px; line-height: 1.4; ">
<div class="clear" style="clear: both; ">&nbsp;</div>
<div id="pretty">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 80px; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">SSIS event handlers are the simplest means of turning an SSIS script into a reliable system that is auditable, reacts appropriately to error conditions, reports progress and allows instrumentation<span lang="EN-US">&nbsp;and monitoring your SSIS packages.&nbsp;</span>T<span lang="EN-US">hey are&nbsp;</span>easy&nbsp;<span lang="EN-US">to implement,&nbsp;</span>and provide a great deal of flexibility. Rob Sheldon once again provides the easy, clear introduction<span lang="EN-US">.</span></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Since the release of SQL Server 2005, SQL Server Integration Services (SSIS) has proven to be an effective tool for managing extract, load, and transform (ETL) operations. However, most of the material you find about developing SSIS packages focuses on the control flow and data flow as they&rsquo;re rendered in Business Intelligence Development Studio (BIDS). But another important&mdash;and often overlooked&mdash;feature in an SSIS package is the event handler.</span></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Event handlers let you run SSIS components on a per</span>-<span lang="EN-US">executable, per</span>-<span lang="EN-US">event basis. For example, suppose your package includes a&nbsp;<b>Foreach Loop</b>&nbsp;container. You can associate one or more SSIS components with each event generated by that container when it is executed. This includes such events as&nbsp;<b>OnError</b>,&nbsp;<b>OnInformation</b>, and<b>OnPostExecute</b>. The components you associate with the container&rsquo;s events are separate from the regular control flow. Consequently, you can configure them specifically to the needs of the associated event handler. This will all become clearer as I demonstrate how to configure an event handler.</span></p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 0in; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><b>Note:</b><span lang="EN-US" style="font-family: Arial, sans-serif; ">&nbsp;In SSIS, an executable is any component you add to the control flow, plus the package itself. The components act as child executables to the package. If you add a component to a container, the container is the parent executable (but the child of the package executable), and the component within the container is the child executable.</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">In this article I explain how to add event handlers to an SSIS package. The package in this case inserts data into two tables I created in the AdventureWorks2008 sample database on a local instance of SQL Server 2008. The first table, People, will be the target of the package after that package extracts data from the Person.Person table in the AdventureWorks2008 database. The second table, RunInfo, will store data that is generated by the event handlers I&rsquo;ll be adding to the package The following Transact-SQL script includes the CREATE TABLE statements necessary to add both tables:</span></p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; font-size: 8pt; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">IF</span><span lang="EN-US" style="font-family: 'Courier New'; ">&nbsp;<span style="color: fuchsia; ">OBJECT_ID</span><span style="color: gray; ">(</span><span style="color: red; ">&#8216;People&#8217;</span><span style="color: gray; ">,</span>&nbsp;<span style="color: red; ">&#8216;U&#8217;</span><span style="color: gray; ">)</span>&nbsp;<span style="color: gray; ">IS</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">DROP</span><span lang="EN-US" style="font-family: 'Courier New'; ">&nbsp;<span style="color: blue; ">TABLE</span>&nbsp;dbo<span style="color: gray; ">.</span>People<span style="color: gray; ">;</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">CREATE</span><span lang="EN-US" style="font-family: 'Courier New'; ">&nbsp;<span style="color: blue; ">TABLE</span>&nbsp;dbo<span style="color: gray; ">.</span>People</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">(</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>PersonID&nbsp;<span style="color: blue; ">INT</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>FirstName&nbsp;<span style="color: blue; ">NVARCHAR</span><span style="color: gray; ">(</span>50<span style="color: gray; ">)</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>LastName&nbsp;<span style="color: blue; ">NVARCHAR</span><span style="color: gray; ">(</span>50<span style="color: gray; ">)</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span><span style="color: blue; ">CONSTRAINT</span>&nbsp;PK_People&nbsp;<span style="color: blue; ">PRIMARY</span>&nbsp;<span style="color: blue; ">KEY</span>&nbsp;<span style="color: blue; ">CLUSTERED&nbsp;</span><span style="color: gray; ">(</span>PersonID&nbsp;<span style="color: blue; ">ASC</span><span style="color: gray; ">)</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">);</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">IF</span><span lang="EN-US" style="font-family: 'Courier New'; ">&nbsp;<span style="color: fuchsia; ">OBJECT_ID</span><span style="color: gray; ">(</span><span style="color: red; ">&#8216;RunInfo&#8217;</span><span style="color: gray; ">,</span>&nbsp;<span style="color: red; ">&#8216;U&#8217;</span><span style="color: gray; ">)</span>&nbsp;<span style="color: gray; ">IS</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">DROP</span><span lang="EN-US" style="font-family: 'Courier New'; ">&nbsp;<span style="color: blue; ">TABLE</span>&nbsp;dbo<span style="color: gray; ">.</span>RunInfo<span style="color: gray; ">;</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">&nbsp;</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">CREATE</span><span lang="EN-US" style="font-family: 'Courier New'; ">&nbsp;<span style="color: blue; ">TABLE</span>&nbsp;dbo<span style="color: gray; ">.</span>RunInfo</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">(</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>RunID&nbsp;<span style="color: blue; ">INT</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL</span>&nbsp;<span style="color: blue; ">IDENTITY</span><span style="color: gray; ">,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>TaskID&nbsp;<span style="color: blue; ">NVARCHAR</span><span style="color: gray; ">(</span>50<span style="color: gray; ">)</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>TaskName&nbsp;<span style="color: blue; ">NVARCHAR</span><span style="color: gray; ">(</span>50<span style="color: gray; ">)</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>TaskTime&nbsp;<span style="color: blue; ">DATETIME</span>&nbsp;<span style="color: gray; ">NOT</span>&nbsp;<span style="color: gray; ">NULL</span>&nbsp;<span style="color: blue; ">DEFAULT</span><span style="color: gray; ">(</span><span style="color: fuchsia; ">GETDATE</span><span style="color: gray; ">())</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span><span style="color: blue; ">CONSTRAINT</span>&nbsp;PK_RunInfo&nbsp;<span style="color: blue; ">PRIMARY</span>&nbsp;<span style="color: blue; ">KEY</span>&nbsp;<span style="color: blue; ">CLUSTERED&nbsp;</span><span style="color: gray; ">(</span>RunID&nbsp;<span style="color: blue; ">ASC</span><span style="color: gray; ">)</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">);&nbsp;</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">After I added the two tables to the database, I created the SSIS package. Figure 1 shows the control flow of the package after I added the necessary components. As the figure indicates, the control flow includes an&nbsp;<b>Execute SQL&nbsp;</b>task to truncate the People table and includes a&nbsp;<b>Sequence</b>&nbsp;container that contains two&nbsp;<b>Data Flow</b>&nbsp;tasks.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image002.jpg" width="624" height="530" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 1: Configuring the control flow</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Notice that Figure 1 also shows the&nbsp;<b>AdventureWorks2008</b>&nbsp;connection manager, which is an&nbsp;<b>OLE DB</b>connection manager that connects to the AdventureWorks2008 database on the local instance of SQL Server 2008. I use this connection manager for all my connections.</span></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Next I configured the two data flows. The&nbsp;<b>Load Data 1</b>&nbsp;data flow, shown in Figure 2, uses an&nbsp;<b>OLE DB&nbsp;</b>source to retrieve data from the Person.Person table and a&nbsp;<b>SQL Server</b>&nbsp;destination to insert data into the People table.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image004.jpg" width="624" height="529" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 2: Configuring the Load Data 1 data flow</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">When I configured the&nbsp;<b>OLE DB&nbsp;</b>source, I used the following SELECT statement to retrieve data from the Person.Person table:</span></p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; font-size: 8pt; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">SELECT</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>BusinessEntityID<span style="color: gray; ">,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>FirstName<span style="color: gray; ">,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>LastName</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">FROM</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>Person<span style="color: gray; ">.</span>Person</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">WHERE</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>BusinessEntityID&nbsp;<span style="color: gray; ">&lt;</span>&nbsp;10000<span style="color: gray; ">;</span></span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Notice that I retrieve only those rows whose BusinessEntityID value is less that 10000. The&nbsp;<b>Load Data 2</b>&nbsp;data flow is identical to&nbsp;<b>Load Data 1</b>, except that I used the following SELECT statement:</span></p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; font-size: 8pt; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">SELECT</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>BusinessEntityID<span style="color: gray; ">,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>FirstName<span style="color: gray; ">,</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>LastName</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">FROM</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>Person<span style="color: gray; ">.</span>Person</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">WHERE</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span><span>&nbsp;&nbsp;</span>BusinessEntityID&nbsp;<span style="color: gray; ">&gt;=</span>&nbsp;10000<span style="color: gray; ">;</span></span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">As you can see, this time I&rsquo;m retrieving only those rows whose BusinessEntityID value is greater than or equal to 10000. I set up the two data flows in this way to better demonstrate the relationship between executables and event handlers in the SSIS package. You can download<a href="http://www.simple-talk.com/content/file.ashx?file=5069" style="text-decoration: none; color: rgb(204, 102, 51); ">&nbsp;the completed package&nbsp;</a>from the speech-bubble&nbsp;at the head of this article, or you can simply create the package yourself. If you&rsquo;re uncertain how to create an SSIS package or configure any of these components, be sure to check out SQL Server Books Online. Once you&rsquo;ve set up your package, you&rsquo;re ready to add the event handlers.</span></p>
<h1 style="font-family: 'Times New Roman', Times, serif; margin-left: 0px; font-size: 19px; "><span lang="X-NONE">Selecting an Executable and Event</span></h1>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">You configure your event handlers on the&nbsp;<b>Event Handlers</b>&nbsp;tab of SSIS Designer. The tab, shown in Figure 3, provides access to the package&rsquo;s executables and to the events associated with each executable. The tab also provides the design surface necessary to add components to an event handler, just as you would add components to the control flow.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image006.jpg" width="623" height="533" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 3: Accessing the Event Handlers tab</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">When you first access the Event Handlers tab, the selected executable is the package itself, which in this case, I&rsquo;ve named&nbsp;<b>EventHandlersPkg</b>. In addition, the selected event is&nbsp;<b>OnError</b>. As a result, any components you would add to the design surface at this point would be specific to this combination of this executable and event pair. To view all the executables, click the down-arrow on the&nbsp;<b>Executable</b>&nbsp;text box and then expand the list of executables, as shown in Figure 4.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image008.jpg" width="624" height="533" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 4: Viewing the package executables</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Notice that the executables are listed hierarchically, with&nbsp;<b>EventHandlersPkg</b>&nbsp;at the top of the hierarchy and the<b>Execute SQL&nbsp;</b>task (<b>Truncate People table</b>) and the&nbsp;<b>Sequence</b>&nbsp;container (<b>Load People data</b>) at the second level of the hierarchy. At the third level, below the&nbsp;<b>Sequence</b>&nbsp;container, are the two&nbsp;<b>Data Flow</b>&nbsp;tasks (<b>Load Data 1</b>&nbsp;and&nbsp;<b>Load Data 2</b>). For each executable, a folder named Event Handlers is listed. Any event handlers you configure for an executable are listed in that folder, with the event handlers sorted by event.</span></p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 0in; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><b>Note:</b><span lang="EN-US" style="font-family: Arial, sans-serif; ">&nbsp;The sources, transformations, and destinations you add to a data flow are not executables. They are all part of the&nbsp;<b>Data Flow</b>&nbsp;executable, which is why these components are not included in the list of executables on the&nbsp;<b>Event Handlers</b>&nbsp;tab.</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">For each executable, you will find a list of events in the&nbsp;<b>Event handler</b>&nbsp;list. The list includes all the events associated with the selected executable. To select an event for an executable, click the down-arrow in the&nbsp;<b>Event handler&nbsp;</b>list, shown in Figure 5, and then select the event.</span></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">&nbsp;</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image010.jpg" width="624" height="530" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 5: Viewing the package events</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">When working on the design surface of the&nbsp;<b>Event Handlers</b>&nbsp;tab, you are always working with a specific executable-event pair. That means, in order to configure an event handler, you must first select an executable and then select the event. For example, if you refer to Figure 6, you&rsquo;ll see that I&rsquo;ve selected the&nbsp;<b>Truncate People table</b>&nbsp;executable and then selected the&nbsp;<b>OnError</b>&nbsp;event. As a result, any components I add to this executable-event pair will run whenever the&nbsp;<b>Truncate People table</b>&nbsp;executable generates an&nbsp;<b>OnError</b>&nbsp;event.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image012.jpg" width="624" height="534" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 6: Selecting an executable and event handler</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Once you&rsquo;ve selected your executable-event pair, you&rsquo;re ready to add your components, so let&rsquo;s take a look at how you do that.</span></p>
<h1 style="font-family: 'Times New Roman', Times, serif; margin-left: 0px; font-size: 19px; "><span lang="X-NONE">Configuring the Event Handler</span></h1>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">If you refer back to Figure 6, you&rsquo;ll notice that the design surface includes a link that instructs you to click it in order to create an event handler for that specific event and executable. You&rsquo;ll be presented with this link for any executable-event pair for which an event handler has not been configured. You must click this link to create the event handler and add any components.</span></p>
<div class="note" style="border-bottom-width: medium; border-bottom-style: none; border-bottom-color: initial; border-left-color: gray; border-left-width: 2.25pt; border-left-style: solid; padding-bottom: 0in; padding-left: 6pt; padding-right: 0in; margin-left: 28.35pt; border-top-width: medium; border-top-style: none; border-top-color: initial; margin-right: 0in; border-right-width: medium; border-right-style: none; border-right-color: initial; padding-top: 0in; ">
<p class="note" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 0in; font-size: 12px; border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-top-color: silver; border-top-width: 1px; border-top-style: solid; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 10px; "><b>Note:</b><span lang="EN-US" style="font-family: Arial, sans-serif; ">&nbsp;Once you click the link on the design surface for a specific executable-event pair, an event handler is created, even if you don&rsquo;t add a component. To delete an event handler for a specific executable-event pair, click the&nbsp;<b>Delete</b>&nbsp;button to the right of the&nbsp;<b>Event handler</b>&nbsp;text box.</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">The first event handler we&rsquo;ll create is for the&nbsp;<b>Load Data 1</b>&nbsp;executable and the&nbsp;<b>OnPostExecute</b>&nbsp;event. After you select the executable-event pair and click the link, you&rsquo;re ready to go. For the&nbsp;<b>EventHandlersPkg&nbsp;</b>package, I&rsquo;ve added an<b>Execute SQL&nbsp;</b>task, as shown in Figure 7. You add the task just as you would add any component to the control flow.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image014.jpg" width="624" height="531" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 7: Adding an Execute SQL task to an event handler</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">When you configure an event handler, you can use any of the system or user variables available to the executable, so let&rsquo;s look at the variables available to the&nbsp;<b>Load Data 1&nbsp;</b>executable. To view these variables, open the&nbsp;<b>Variables</b>pane in SSIS Designer by clicking&nbsp;<b>Variables</b>&nbsp;in the&nbsp;<b>SSIS</b>&nbsp;menu. Then, in the&nbsp;<b>Variables</b>&nbsp;pane, click&nbsp;<b>Show System Variables</b>&nbsp;to list all variables available to your event handler components, as shown in Figure 8.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image016.jpg" width="623" height="592" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 8: Viewing the variables in the Variables pane</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">In this case, we want to use the&nbsp;<b>SourceID</b>&nbsp;and&nbsp;<b>SourceName</b>&nbsp;system variables to identify the components that are generating the&nbsp;<b>OnPostExecute</b>&nbsp;events, which is what we&rsquo;ll log to the RunInfo table. We&rsquo;ll be adding the variables in the&nbsp;<b>Execute SQL&nbsp;</b>task, so let&rsquo;s look at how you configure that task. Figure 9 shows the&nbsp;<b>General</b>&nbsp;page of the&nbsp;<b>Execute SQL Task</b>&nbsp;editor.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image018.jpg" width="624" height="576" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 9: General tab of the Execute SQL Task Editor</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Notice that I&rsquo;ve specified the&nbsp;<b>AdventureWorks2008</b>&nbsp;connection manager in the&nbsp;<b>Connection</b>&nbsp;property. Then, in the<b>SQLStatement</b>&nbsp;property, I added the following INSERT statement:</span></p>
<div class="listing" style="border-bottom-color: rgb(202, 202, 202); border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: rgb(202, 202, 202); border-left-width: 1px; border-left-style: solid; padding-bottom: 10px; background-color: rgb(249, 249, 249); padding-left: 3px; padding-right: 3px; font-family: 'Courier New', Courier, monospace; margin-left: 20px; font-size: 8pt; border-top-color: rgb(202, 202, 202); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(202, 202, 202); border-right-width: 1px; border-right-style: solid; padding-top: 10px; ">
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">INSERT</span><span lang="EN-US" style="font-family: 'Courier New'; ">&nbsp;<span style="color: blue; ">INTO</span>&nbsp;RunInfo</span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: gray; ">(</span><span lang="EN-US" style="font-family: 'Courier New'; ">TaskID<span style="color: gray; ">,</span>&nbsp;Taskname<span style="color: gray; ">)</span></span></p>
<p style="text-align: left; font-family: 'Courier New', Courier, monospace; margin-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0px; padding-left: 0px; padding-right: 0px; margin-bottom: 0px; padding-top: 0px; "><span lang="EN-US" style="color: blue; ">VALUES&nbsp;</span><span lang="EN-US" style="font-family: 'Courier New'; color: gray; ">(</span><span lang="EN-US" style="font-family: 'Courier New'; ">?<span style="color: gray; ">,</span>&nbsp;?<span style="color: gray; ">);</span></span><span lang="EN-US" style="color: gray; ">&nbsp;</span></p>
</div>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">As you can see, I&rsquo;ve included two question mark placeholders in the VALUES clause. The placeholders allow you to insert the values from the&nbsp;<b>SourceID</b>&nbsp;and&nbsp;<b>SourceName</b>&nbsp;system variables into the RunInfo table. However, to do this, you must also map the variables&nbsp; to the statement. Figure 10 shows the&nbsp;<b>Parameter Mapping</b>&nbsp;page of the<b>Execute SQL Task</b>&nbsp;editor, which includes a listing for each variable that will be used by the INSERT statement.</span></p>
<p class="illustration" style="text-align: center; font-family: Arial, Helvetica, sans-serif; margin-left: 0px; font-size: 12px; margin-bottom: 0px; "><span lang="EN-US"><img src="http://www.simple-talk.com/iwritefor/articlefiles/1283-clip_image020.jpg" width="624" height="502" alt="" /></span></p>
<p class="caption" style="text-align: left; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 11px; margin-top: 0px; font-weight: bold; ">Figure 10: Parameter Mapping tab of the Execute SQL Task Editor</p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">As Figure 10 indicates, both variables are input variables configured with the NVARCHAR data type. In addition, the name of the first variable (<b>SourceID</b>) is 0, and the name of the second variable (<b>SourceName</b>) is 1. This follows the naming conventions necessary to pass parameter values into the INSERT statement. That&rsquo;s all there is to configuring the&nbsp;<b>Execute SQL&nbsp;</b>task. And that&rsquo;s also the only component I added to the&nbsp;<b>Load Data 1</b>&nbsp;executable. However, I also configured the same event for the&nbsp;<b>Load Data 2</b>&nbsp;executable and then added an&nbsp;<b>Execute SQL&nbsp;</b>task to the event handler, set up just like the task in&nbsp;<b>Load Data 1</b>. That means when the SSIS package runs, it will execute two event handlers, one for each data flow.</span></p>
<h1 style="font-family: 'Times New Roman', Times, serif; margin-left: 0px; font-size: 19px; "><span lang="X-NONE">Running the SSIS Package</span></h1>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Once you&rsquo;ve configured your event handlers, you&rsquo;re ready to run the SSIS package. Running a package that contains event handlers is no different from running any other type of package. The event handlers will be executed as long as the executable issues the event for which SSIS components have been configured. That means, in this case, as long as the&nbsp;<b>Data Flow</b>&nbsp;tasks run successfully, the&nbsp;<b>OnPostExecute</b>&nbsp;events will be issued and the&nbsp;<b>Execute SQL</b>&nbsp;tasks will run. The INSERT statements within those tasks will then add the variable information to the RunInfo table.</span></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">After I ran the&nbsp;<b>EventHandlersPkg</b>&nbsp;package the first time, I queried the RunInfo table and received the following results:</span></p>
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; border-bottom-color: initial; border-bottom-width: medium; border-bottom-style: none; border-left-color: initial; border-left-width: medium; border-left-style: none; margin-left: 18pt; border-top-color: initial; border-top-width: medium; border-top-style: none; border-right-color: initial; border-right-width: medium; border-right-style: none; ">
    <tbody>
        <tr style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; ">
            <td valign="top" width="61" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-color: silver; border-left-width: 1pt; border-left-style: solid; padding-bottom: 0cm; padding-left: 5.4pt; width: 45.9pt; padding-right: 5.4pt; border-top-color: silver; border-top-width: 1pt; border-top-style: solid; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><b><span lang="EN-US">RunID</span></b></p>
            </td>
            <td valign="top" width="300" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 225pt; padding-right: 5.4pt; border-top-color: silver; border-top-width: 1pt; border-top-style: solid; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><b><span lang="EN-US">TaskID</span></b></p>
            </td>
            <td valign="top" width="99" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 74.55pt; padding-right: 5.4pt; border-top-color: silver; border-top-width: 1pt; border-top-style: solid; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><b><span lang="EN-US">TaskName</span></b></p>
            </td>
            <td valign="top" width="154" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 115.35pt; padding-right: 5.4pt; border-top-color: silver; border-top-width: 1pt; border-top-style: solid; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><b><span lang="EN-US">TaskTime</span></b></p>
            </td>
        </tr>
        <tr style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; ">
            <td valign="top" width="61" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-color: silver; border-left-width: 1pt; border-left-style: solid; padding-bottom: 0cm; padding-left: 5.4pt; width: 45.9pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">1</span></p>
            </td>
            <td valign="top" width="300" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 225pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">{85B4ED54-D20D-4E90-B60C-E0151D7B1348}</span></p>
            </td>
            <td valign="top" width="99" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 74.55pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">Load Data 1</span></p>
            </td>
            <td valign="top" width="154" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 115.35pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">2011-04-17 19:25:13.370</span></p>
            </td>
        </tr>
        <tr style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; ">
            <td valign="top" width="61" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-color: silver; border-left-width: 1pt; border-left-style: solid; padding-bottom: 0cm; padding-left: 5.4pt; width: 45.9pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">2</span></p>
            </td>
            <td valign="top" width="300" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 225pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">{057C0C52-99B1-4B96-BDC8-923A6A85CCBE}</span></p>
            </td>
            <td valign="top" width="99" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 74.55pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">Load Data 2</span></p>
            </td>
            <td valign="top" width="154" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; font-size: 11px; border-bottom-color: silver; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; border-left-color: initial; padding-bottom: 0cm; padding-left: 5.4pt; width: 115.35pt; padding-right: 5.4pt; border-top-width: medium; border-top-style: none; border-top-color: initial; border-right-color: silver; border-right-width: 1pt; border-right-style: solid; padding-top: 0cm; ">
            <p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 5px; font-size: 11px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; line-height: normal; "><span lang="EN-US">2011-04-17 19:25:13.670</span></p>
            </td>
        </tr>
    </tbody>
</table>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">&nbsp;</span></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">As you can see, the task ID and task names have been added to the table, and as expected, there is one row for each task. If you run the package multiple times, you will see additional rows.</span></p>
<p style="text-align: justify; font-family: Arial, Helvetica, sans-serif; margin-left: 20px; font-size: 12px; "><span lang="EN-US">Although the example I&rsquo;ve demonstrated in this article is very basic, it does show you the power of event handlers to capture a variety of information under specific circumstances. And you can perform other actions as well. For example, in addition to being able to set up a system to audit your packages, you can take such steps as sending an email if an executable issues an&nbsp;<b>OnError</b>&nbsp;event. SSIS event handlers are flexible and provide many options for auditing and monitoring your SSIS packages. And given how easy they are to implement, it is well worth the time and effort to take full advantage of all that event handlers have to offer.</span></p>
</div>
<br />
<br />
This article has been viewed 7579 times.</div>
<div class="authorpanel" style="margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(103, 92, 109); border-right-color: rgb(103, 92, 109); border-bottom-color: rgb(103, 92, 109); border-left-color: rgb(103, 92, 109); background-color: rgb(232, 228, 234); color: rgb(51, 51, 51); font-size: 12px; "><a id="ctl00_MainContent_Author1_lnkImage" title="Robert Sheldon" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); "><img id="ctl00_MainContent_Author1_imgAuthor" class="authorpicture" src="http://www.simple-talk.com/iwritefor/publishers/120.gif" alt="Robert Sheldon" align="left" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; " /></a>
<p style="margin-top: 7px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><strong>Author profile:</strong>&nbsp;<a id="ctl00_MainContent_Author1_lnkName" href="http://www.simple-talk.com/author/robert-sheldon/" style="text-decoration: none; color: rgb(204, 102, 51); ">Robert Sheldon</a></p>
<p style="margin-top: 7px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">After being dropped 35 feet from a helicopter and spending the next year recovering, Robert Sheldon left the Colorado Rockies and emergency rescue work to pursue safer and less painful interests&mdash;thus his entry into the world of technology. He is now a technical consultant and the author of numerous books, articles, and training material related to Microsoft Windows, various relational database management systems, and business intelligence design and implementation. He has also written news stories, feature articles, restaurant reviews, legal summaries, and the novel &#8216;Dancing the River Lightly&#8217;. You can find more information at http://www.rhsheldon.com.</p>
</div>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/database-articles/ssis/ssis-event-handlers-basics/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Snippet Tutorial &#8211; Get File Listings</title>
		<link>http://www.wiseinn.com/index.php/net/c-sharp/programming/c-snippet-tutorial-get-file-listings</link>
		<comments>http://www.wiseinn.com/index.php/net/c-sharp/programming/c-snippet-tutorial-get-file-listings#comments</comments>
		<pubDate>Fri, 24 Jun 2011 21:36:06 +0000</pubDate>
		<dc:creator>wiseinn</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.wiseinn.com/?p=1965</guid>
		<description><![CDATA[&#160;Ok, so can you even begin to tell me how many files you have on your computer? I can&#8217;t either. There are so many reasons you could need to get file listings in C#, and thanks to the&#160;System.IO namespace, doing so is just about as easy as including the namespace itself. Really all you need [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<span class="Apple-style-span" style="font-family: sans-serif; line-height: 16px; ">Ok, so can you even begin to tell me how many files you have on your computer? I can&#8217;t either. There are so many reasons you could need to get file listings in C#, and thanks to the&nbsp;<a href="http://msdn.microsoft.com/en-us/library/system.io.aspx" title=" System.IO Namespace" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(60, 147, 88); text-decoration: none; ">System.IO namespace</a>, doing so is just about as easy as including the namespace itself. Really all you need to do is create a variable, then a loop.</span><span class="Apple-style-span" style="font-family: sans-serif; line-height: 16px; ">
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">So all the magic happens due to a couple of nice and simple classes in the System.IO namespace, called&nbsp;<a href="http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx" title=" DirectoryInfo Class" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(60, 147, 88); text-decoration: none; ">DirectoryInfo</a>&nbsp;and&nbsp;<a href="http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx" title=" FileInfo Class" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(60, 147, 88); text-decoration: none; ">FileInfo</a>. Really, with these two classes you can do a lot of cool stuff, directory and file wise that is. Not only do these classes make file and directory listing really simple, but they are actually more powerful than they seem.</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Anyway, in order to get started, you must first include the System.IO namespace, mainly because it is not used by default. So add it to the top of your code. Next we are going to make a new DirectoryInfo instance, and in this case we are using the root drive of C:\, so your code should look like:</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p>
<div class="geshifilter" style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0.5em; padding-right: 0.5em; padding-bottom: 0.5em; padding-left: 0.5em; display: block; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(236, 239, 255); line-height: 1.3; font-size: 12px; clear: both; ">
<div class="csharp geshifilter-csharp" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; overflow-x: auto; overflow-y: auto; font-family: monospace; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">DirectoryInfo</span>&nbsp;fileListing&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(41, 109, 38); ">=</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(6, 0, 255); ">new</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">DirectoryInfo</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); ">&quot;C:<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); ">\\</span>&quot;</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">;</span></div>
</div>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">This code does exactly what you would think, it takes the directory and allows you to get all kinds of information about it. You can use this one variable to find out all kinds of things, anything from directory permissions to the last modified date. Now, this little snippet will only cover the basics, but when you are looking at more, just remember listing files is only the simplest of things you can do.</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Now that we have our DirectoryInfo object, we can loop through all the files in that directory and do whatever we like with them. In this case, we are just going to fill a listbox with the full file path. To do this, all we need to do is call the<a href="http://msdn.microsoft.com/en-us/library/ms143327.aspx" title=" DirectoryInfo.GetFiles() method" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(60, 147, 88); text-decoration: none; ">GetFiles()</a>&nbsp;method, which returns an array of FileInfo objects. Each FileInfo has a ton of information on each file, but all we really need is the name right now. So our final code might look something like:</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p>
<div class="geshifilter" style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0.5em; padding-right: 0.5em; padding-bottom: 0.5em; padding-left: 0.5em; display: block; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(236, 239, 255); line-height: 1.3; font-size: 12px; clear: both; ">
<div class="csharp geshifilter-csharp" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; overflow-x: auto; overflow-y: auto; font-family: monospace; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">DirectoryInfo</span>&nbsp;fileListing&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(41, 109, 38); ">=</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(6, 0, 255); ">new</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">DirectoryInfo</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); ">&quot;C:<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); ">\\</span>&quot;</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">;</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(6, 0, 255); ">foreach</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">FileInfo</span>&nbsp;file&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(6, 0, 255); ">in</span>&nbsp;fileListing.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">GetFiles</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">{</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
&nbsp; listBox1.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">Items</span>.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">Add</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span>fileListing.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">ToString</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(41, 109, 38); ">+</span>&nbsp;file.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">Name</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">;</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">}</span></div>
</div>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Super simple, but lets be honest with ourselves, how often do you want all the files in a directory? Not very often I would think. Luckily, the GetFiles() method has an argument to limit what files you get. This argument is just a string that you can add a search pattern to. So say we want to search for .txt files. Our updated code would look like so:</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p>
<div class="geshifilter" style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0.5em; padding-right: 0.5em; padding-bottom: 0.5em; padding-left: 0.5em; display: block; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(236, 239, 255); line-height: 1.3; font-size: 12px; clear: both; ">
<div class="csharp geshifilter-csharp" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; overflow-x: auto; overflow-y: auto; font-family: monospace; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">DirectoryInfo</span>&nbsp;fileListing&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(41, 109, 38); ">=</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(6, 0, 255); ">new</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">DirectoryInfo</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); ">&quot;C:<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); ">\\</span>&quot;</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">;</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(6, 0, 255); ">foreach</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">FileInfo</span>&nbsp;file&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(6, 0, 255); ">in</span>&nbsp;fileListing.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">GetFiles</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 0, 0); ">&quot;*.txt&quot;</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">{</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
&nbsp; listBox1.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">Items</span>.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">Add</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span>fileListing.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">ToString</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">(</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span>&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(41, 109, 38); ">+</span>&nbsp;file.<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">Name</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">;</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />
<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 0, 0); ">}</span></div>
</div>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">The one downside to using the search pattern is that you can only use one of them. As far as I know you can only use one search pattern in the string, so in order to get multiple file types, you have to call the method again with a different pattern. That being said, it is not too much of an inconvenience being as easy as it is.</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 14px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">So that is pretty much how you can get the files in a current directory. Super simple and super fast. You can do all kinds of things with the DirectoryInfo and FileInfo classes, so I would check them out if you can. Just don&#8217;t forget to Switch on the Code.</p>
</span></p><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.wiseinn.com/index.php/net/c-sharp/programming/c-snippet-tutorial-get-file-listings/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

