shouldn't variables in a Foreach Loop be resolved automatically?

  • I've been experimenting with a simple loop to read through .csv files in a folder and use 7-zip to create password-protected archives from them, pretty much as described here : http://dataintegrity.wordpress.com/2009/10/13/dynamically-zipping-files-in-ssis

    The for-each loop passes the filename to the first task, which creates the zipped file. That's working fine. But a subsequent File System Task in the loop should then move the zipped file into a different folder. The source and destination folders are specified as variables, exactly as in the article, but when I execute the package I get an error message 'illegal characters in path'. When I put a watch on the source and destination variables, the watch just displays the definition e.g. the destination variable "ZippedFiles" appears to contain the text @[User::DirectoryToZip] + "ZIPPED\\"

    So it looks as if these variables just aren't being resolved.

    I've worked around it by adding a script task to explicitly set these variables e.g. Dts.Variables["User::ZippedFiles"].Value = Convert.ToString(Dts.Variables["User::DirectoryToZip"].Value)

    + "ZIPPED\\";

    But I shouldn't need to be doing that should I? The example in the article doesn't.

  • Did you put the property EvaluateAsExpression to true on the variables?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • OMG. So obvious. Thanks.

    For the benefit of other newbies - that otherwise very useful article tells you to set up some variables like

    ZippedFiles: @[User::DirectoryToZip] + “ZIPPED\\”

    Those variables need to be set with the property EvaluateAsExpression=True and the Expression (NOT the Value) set to the string-concatenation code e.g.

    @[User::DirectoryToZip] + “ZIPPED\\”

  • deeby (6/5/2014)


    OMG. So obvious. Thanks.

    For the benefit of other newbies - that otherwise very useful article tells you to set up some variables like

    ZippedFiles: @[User::DirectoryToZip] + “ZIPPED\\”

    Those variables need to be set with the property EvaluateAsExpression=True and the Expression (NOT the Value) set to the string-concatenation code e.g.

    @[User::DirectoryToZip] + “ZIPPED\\”

    Luckily in SSIS 2012 this has become more transparent. Variables have a seperate value and expression column and once you put something in the expression column, the property EvaluateAsExpression is set to true.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply