Link to home
Start Free TrialLog in
Avatar of JOELL MERRITT
JOELL MERRITT

asked on

SSIS Script Task not changing values

I have a SSIS package that I am testing to see if a File Exists and if it does, then I do not want to continue the package.   I have written a Script Task inside a For each Loop that connects to my Data Flow task.   All works well for a new file.   But, when I am checking for an existing file, I dont get an error from the Script task but it does not return the correct value from what I learned in the Message Box window.  And, the Data Flow tasks kicks off, but this is the weird part, the For each Loop and the last task called File System task fails as they should!   I need to know how to make the Data Flow task fail.  

I have set up a User::Flag as a ReadWriteVariables in the script task to be a 1 when the file exists and 0 when it does not.   I also have a variable User::VarArchiveFullPath as a ReadOnlyVariables.   ( I used the C# 2010 version of the script)

Here is my script.   What am I doing wrong that causes the flag to not change and always send a success.  It never fails!


        public void Main()
        {

            string filefullpath = Dts.Variables["User::VarArchiveFullPath"].Value.ToString();
            try
            {
                if (File.Exists(filefullpath))
                {
                    Dts.Variables["User::Flag"].Value = true;
                }
                else
                {
                    Dts.Variables["User::Flag"].Value = false;
                }

                Dts.TaskResult = (int)ScriptResults.Success;
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
                Dts.TaskResult = (int)ScriptResults.Failure;
            }
        }


Thanks in advance!
Avatar of JOELL MERRITT
JOELL MERRITT

ASKER

Nevermind.  I finally got it to work.   The only thing I can think of is that I put the file extension on the end of the variable file names.
Hai,
Thanks for sharing nice blog. Coding is very helpful. Hope this blog https://mindmajix.com/ssis/ssis-script-task may also be helpful, Please go through it.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.