开发者

SSIS 2008 Check for flat file and take action if found

开发者 https://www.devze.com 2023-04-05 08:05 出处:网络
I have a package that needs to check if a file exists in a folder and if the file does exist then take a branch that will import the file to SQL Server and execute some stored procedures to process it

I have a package that needs to check if a file exists in a folder and if the file does exist then take a branch that will import the file to SQL Server and execute some stored procedures to process it. If the file does not exist then just end the current run of the package without error. I have all parts working just fine except for the file detection and branching depending on the results. (In other words currently it just runs as if the file is there and does the rest). I know how to use a script task to detect for the file and return an error if not found - I need to开发者_如何学Go know how to make the main package just end without error in that case or go on and do the import and the rest of the processing if the file was found.


You could use a Foreach Loop container in the Control flow tab. Loop through a folder for a given pattern (say *.csv). Set the flat file connection manager to use the filepath obtained from the For each loop container as the connection string.

In this setup, the data flow task within the For each loop container will execute only if a file is found. Otherwise, it will end the process silently without any errors.

Here are few other SO questions where I have provided some examples about looping files using Foreach Loop container.

Creating an Expression for an Object Variable?

How can I load a large flat file into a database table using SSIS?

Hope that gives you an idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消