Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My technology blog on SQL Server, TSQL, XML, FILESTREAM and other areas of SQL Server.
Browse by Tags · View All
XML 112
TSQL 69
XQuery 69
XQuery Functions 67
XQuery Training 65
XQuery in TSQL 64
XQuery Tutorial 63
SQL Server XQuery 63
XQuery-Labs 57
BRH 38

Archive · View All
September 2008 32
August 2008 30
July 2008 21
August 2009 19
June 2009 19
May 2010 18
January 2009 15
January 2010 14
October 2008 14
June 2008 13

SSIS-Handling package failures when the input file is not found

Jul 18 2012 7:56PM by Jacob Sebastian   

This post is inspired by a question asked in my blog this morning, about handling file-not-found errors from an SSIS package. A typical use case is as follows. An SSIS package is scheduled to run at every X minutes which processes files coming into a folder. However, a file may not be present every time the package runs. If a file is available it should be processed. If the file is not found, the package should exit gracefully, without generating an error.

There may be different ways of handling this. A few that I am aware of are

  1. Creating a script task to check the existence of the file before proceeding to the actual import
  2. Creating a for-each-loop that iterates over the files present in the folder
  3. Using a 3rd party SSIS component that performs a file check

This post tries to demonstrate the option #1 listed above: handling the file-not-found case using a script task.

Checking the existence of the file using a script task

To start with, let us create two variables; one for the file name and another a boolean flag that indicates whether the file exists or not. The script task will turn this variable into true or false depending upon the existence of the file. Execution will continue to the next step only if the file exists.

var

Next, let us add a script task and data flow task into the package designer.

script

Now, let us add a constraint that ensures that the data flow task is executed only if the value of the variable Exists is set to true. Keep in mind that we will change the value of this variable from the script task depending upon the presence of absence of the file.

constraint

Let us now proceed with writing the script. Before we actually move into the script designer, open the properties of the script task and set the read-only and read-write variables.

script-editor

Next, click on the button edit script which will open the script editor.

To start with we will need the following using statement.

using System.IO;

Next, add the following code into the main() function.

string file = Dts.Variables["User::FileName"].Value.ToString();
if (File.Exists(file))
{
    Dts.Variables["User::Exists"].Value = true;
}
else
{
    Dts.Variables["User::Exists"].Value = false;
}
Dts.TaskResult = (int)ScriptResults.Success;

Well, we are now ready for testing. Run the code in the presence and absence of the input file and ensure that it works.

Tags: 


Jacob Sebastian
1 · 100% · 32235
8
 
 
0
Refreshed
 
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"SSIS-Handling package failures when the input file is not found" rated 5 out of 5 by 8 readers
SSIS-Handling package failures when the input file is not found , 5.0 out of 5 based on 8 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]