Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1708
  • Last Modified:

Increment Variable within Foreach File Enumerator

Hi,

I have a 2008 SSIS package that reads a dynamic number of files and loads it into a table.  I am using the Foreach File Enumerator that runs a data flow to populate a table.  I also have logic to move each file processed into an \archive folder and rename it with a timestamp.  I also added some event handling in the case the load errors, in which I store the ErrorDescription into a variable object as an ArrayList in the OnError event, then consolidate the ArrayList descriptions into one big string to send via an email from the OnPostExecute event.

One of the issues I have is that if this becomes scheduled, and there happens to be no files to process in the source directory, the SSIS package will run, but still kicks off the event handling portion, which I do not want it to do.  I would like to somehow not make the event handling execute if there are no source files to process so no email is sent out.

I was thinking of creating a variable that counts how many times the Foreach Enumerator runs; if no files exist, then the value would be zero, then I can use that to prevent the email script task being executed.  The problem is, I do not know how to increment a variable.  I tried creating a script task that takes a variable as the input, but it won't let me use the same one as output.

I'm sure this is pretty easy to do; I just happen to suck and only have about 1.5 days of SSIS experience.

Thanks!
0
gometang
Asked:
gometang
  • 3
  • 2
1 Solution
 
Reza RadCommented:
as you said solution is to create an script task inside foreach loop
but don't use your increment variable as readonly variable, you must set it in ReadAndWrite variables property and inside this script task plus one to variable.
does it make sense to you or not?

0
 
Reza RadCommented:
I created a sample for you
look at attachements



1.JPG
2.JPG
3.JPG
0
 
gometangAuthor Commented:
Perfect!  Btw, how did you get the "Variable=17" window to pop up?

Thanks!

Gome
0
 
Reza RadCommented:
It's just a message box
in second script task
in Main() method
write code below:
MessageBox.Show("Variable="+Dts.Variables["User::Variable"].Value.ToString());

Glad to help,
Regards,

0
 
gometangAuthor Commented:
A+++
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now