1

I have a very simple ssis task, currently it is just a flat file connection and a bulk insert task to update a table. I cannot figure out how to ensure the flat file was created today before continuing with the bulk insert.

jarlh
  • 42,561
  • 8
  • 45
  • 63
user2369812
  • 779
  • 2
  • 9
  • 21

1 Answers1

0

In your Data Flow block, add a Script component, like this:

enter image description here

Add two variables, one for your file name and one for the result of the script: enter image description here

Next, configure your script as follows:

enter image description here

Now, you can add the following expression to the arrow between the script component and your data flow block:

enter image description here

Your code in the script itself would be:

public void Main()
    {
        string fileName = Dts.Variables["FileName"].Value.ToString();
        FileInfo fi = new FileInfo(fileName);

        Dts.Variables["FileWasCreatedToday"].Value = fi.CreationTime >= DateTime.Now.Date;

        // Another option would be to set this to fail if it's not created today. This will fail the whole package.
        Dts.TaskResult = (int)ScriptResults.Success;
    }

Edit: If you want it to send you an email in the case of a failure, just create a second link from the Script Task to your Send Mail Task with the following expression: !@[User::FileWasCreatedToday]. Like below:

enter image description here