1

I have this script task I'm using to assign a value to a string variable to be used as a connection string for a flat file. The variable has a default path to a blank file containing only the header row, if the file exists in my incoming directory, the script should change the variable value to the path of that file. I've created a breakpoint and have stepped through this code line by line checking the value of files[0] at the line to assign the value to var, it contains the correct string value. Unfortunately, the variable doesn't have the changed value after the script exits. I do have the variables checked as read/write instead of just read. Any ideas where I'm going wrong?

public void Main()
{
    // TODO: Add your code here

    string incoming = Dts.Variables["User::DirIncoming"].Value.ToString();

    foreach (Variable var in Dts.Variables)
    {
        if (var.QualifiedName.StartsWith("User::Conn"))
        {
            string varName = var.QualifiedName.Substring(10);
            string[] files = Directory.GetFiles(incoming, varName + "*");
            if (files.Length > 0)
            {
                var.Value = files[0];
            }
        }
    }

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

1 Answer 1

1

I didn't realize that it mattered that my default value for my variable was being assigned via an expression, therefore I needed to change my expression instead of my value. I changed the line in question to the below code, and all is great now. Thanks everyone for taking a look.

var.Expression = $"\"{files[0]}\"".Replace("\\","\\\\");

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.