0

I try to simply change value of SSIS variable doing this code in ScriptTask:

        string path = Dts.Connections["BazyPobrane"].ConnectionString.ToString();
        string[] nameZIParray = Directory.GetFiles(path, "*.ZIP");
        string[] nameRARarray = Directory.GetFiles(path, "*.RAR");

        foreach (string nameZIP in nameZIParray) //search new ZIP
        {
            if (File.GetCreationTime(nameZIP) > DateTime.Now.AddDays(-1))
            {
                Dts.Variables["User::NazwaPliku"].Value = Path.GetFileName(nameZIP);
            }

        }
        foreach (string nameRAR in nameRARarray) //search new RAR
        {
            if (File.GetCreationTime(nameRAR) > DateTime.Now.AddDays(-1))
            {
                Dts.Variables["User::NazwaPliku"].Value = Path.GetFileName(nameRAR);
            }

        }
        Dts.TaskResult = (int)ScriptResults.Success;

After executing ScriptTask it simply don't change the variable Value. Debug mode seems fine. Maybe i miss some component settings? Thx!

1
  • Did you add the variable to the ReadWriteVariables of your script task? Commented Apr 11, 2012 at 12:31

2 Answers 2

1

Some things to check:

  1. Are you sure the variable isn't changing? If you put a subsequent script task with a MessageBox in place, does it show the correct value?

  2. I don't think you need the variable type, i.e. remove "user::"

  3. Make sure the variable is in the ReadWriteVariables property, as suggested by @OcasoP

  4. What's the scope of the variable? Make sure you don't have two copies at different scopes, or that at least the one you do have is visible from the scope of the script

  5. You could try locking the variable before writing to it (which should be equivalent to (3) above)

Code example for the last point:

IDTSVariables100 variables = null;
this.VariableDispenser.LockOneForWrite("NazwaPliku",ref variables);
variables[0].Value = myValue;
variables.Unlock();
Sign up to request clarification or add additional context in comments.

1 Comment

first point was most simple and helpful. MessegeBox showed me real Value of Variable! Seems SSIS Variable window don't refresh fast enough and i was suggested by this one and following component error. Thank You all for your help!
0

debug your script task adding MsgBox(variable_name) and see its value through the execution. Best debugging option :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.