Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Triggering SSIS package based on a file existence

Author  Topic 

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-04-29 : 14:34:41
I am trying to trigger SSIS package if a file is present in a folder, can I use any of the SSIS tasks in doing that??
Thanks!!

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2008-04-29 : 16:41:19
Yes (some options):
1) File.Exists(file path) 'Script Task
2) ForEach File Enumerator
3) File Watcher Task 'http://www.sqlis.com/23.aspx
Go to Top of Page

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-04-29 : 16:45:46
How can I use ForEach File Enumerator, please send me an example I can refer to. Thanks much.
Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2008-04-29 : 16:49:55
Here's one example http://www.sqlis.com/55.aspx
or
Google http://www.google.com/search?hl=en&q=ssis+ForEach+File+Enumerator
Go to Top of Page

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-04-29 : 17:35:11
Thanks for the speedy response, this is really valuable info.
Actually here is what I need:
As soon as a excel file is present in the source folder, the SSIS package should start executing. The source folder will have either 1 or many excel files as soon as the excel file(s) is present in the folder the SSIS package should execute.
Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2008-04-29 : 17:55:38
You may need File Watcher Task (free download) to kick off your SSIS or have a SSIS package scheduled every so many minutes (resource hog) that kicks off SSIS that processes your file. You can be creative on your solution but either way you design it you need something to watch the files come in.
Go to Top of Page

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-04-30 : 15:49:55
Installed File watcher task, then created a new SSIS package by adding the file watcher task in the control flow, below are my setting's inside the file watcher task editor:
2. Options
Filter - *.*
Find Existing Files - True
Timeout warning - False
3. Path
Path input type: Direct imput
Path - \\server1\Sourcefolder
Include subdirectories - False
Actually my understanding about this task is:
This file watcher task will constantly check for the file and then will execute the SSIS package.
If my understanding is correct, then where do we specify the name of the SSIS package?? And also do we need this SSIS package which has the File watcher task to run every 5 minutes or so, so that it can keep checking for the file existence.
Please help, thanks!!
Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2008-04-30 : 16:15:25
Have precedence contraint between FWT and Execute Package Task (EPT) where if OutputVariableName not empty then file is present, thus EPT executes. EPT connection can be SQL Server or File System which basically you point to using "Location" section.

Also, depending on your flow/logic instead of executing another SSIS package you can execute Data Flow Task (data processing done here).
Go to Top of Page

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-04-30 : 17:51:14
I linked up the File watcher task and the Exec package task(Filesystem - with the desired package that should execute when true).
Do I need to schedule this package1 which has FWT and EPT to run continuously so that when it finds the file in the source folder, the package1 will execute??
If there is no file in the folder, the package will keep running(alomost like in hung mode) and only when the file is present then the package will complete execution, and once it completes execution how does it start executing again?
Can we do something like this:
1. Schedule the package to run say every 5 minutes
2. Once the file is present the desired package will execute which is linked to the file watcher task, if not the desired package will not run and the package1 should stop.
Thanks much!!

Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2008-05-01 : 12:26:51
Unfortunately, yes. Also, be aware that FWT can cause memory leak and it's been discussed in the SSIS community. It sounds like you can avoid using FWT altogether and perhaps redesign your logic and use ForEach File Enumerator to check if file exists or not. Then you can use SQL Agent to run package every n minutes. Having FWT and SQL job is redundant due its nature of file checking mechanism at certain time interval.

Another option you can check is WMI Task which also checks for file existence but again that requires some sort of start and restart of the package. There's also .NET File Watcher option you can research which can also detects file arrival and such. Try different approach and see which one fits best and efficient. Sorry if this does not help much to you.
Go to Top of Page

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-05-01 : 17:13:30
In order for FWT to check for file existence we need to schedule it to run right? Without scheduling/running can it check for file existence?
How can I use For each file enumerator for file existence?
Thanks for your responses.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-01 : 17:16:57
Can FWT launch an executable once the file is found? If so, then you should launch the DTS package from FWT. Otherwise you'll need to run the DTS package frequently.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2008-05-02 : 08:01:04
Solution #1:
Correct, FWT needs to be running/scheduled (Package1 job fire every n minutes) and it needs to be restarted once data processing (eg Data Flow) is done. My thought of the restart is to add "Exec SQL Server Agent Job Task" (under Maintenace Plan Tasks) to run the same package. So to simplify these are the task items: FWT > Data Flow > Exec Agent Task. I have not fully tested this flow but worth a try I think.

Solution #2 (my personal pick):
This is a shortcut to solution #1. Instead of FWT detecting incoming files you use "Foreach File Enumerator" container. In the container set Variable Mappings to a string variable which holds the file location. Within the container you can put your Data Flow/data processor and will automatically loops out once file no longer exists. So to make this work it still needs to be scheduled and run every n minutes, however, the difference is that FWT is not needed since the container will look for the file itself. So the task items: Foreach Loop > Data Flow

Setup #1 (Data Flow inside Foreach container) -
Variables (Package level), Name = myFile, Data Type = String
Variable Mappings (Foreach Loop), Variable = User::myFile, Index = 0

Setup #2 (Data Flow outside Foreach container) -
Variables (Package level), Name = myFile, Data Type = String
Variable Mappings (Foreach Loop), Variable = User::myFile, Index = 0
Precedence Contraint (between Foreach Loop and Data Flow), Evaluation Expression = Constraint, Expression = @[User::myFile]!="" (proceed if myFile value is not empty)

Of course you can use Script task to look for files too (System.IO.File.Exists(myFile) but it's up to you.

Hope this helps.
Go to Top of Page

SSISJoost
Starting Member

9 Posts

Posted - 2011-03-13 : 16:17:47
Here is a C# Script Task example of checking if a file exists:
http://microsoft-ssis.blogspot.com/2011/03/get-file-properties-with-ssis.html
Go to Top of Page
   

- Advertisement -