please help assigning a SSIS variable using c#

  • Hi folks,

    I'm not sure if I'm going this correctly, but I am trying to assign a variable in a script task using c#. I've added this:

    public void Main()

    {

    int testvar = 1;

    Dts.Variables["User::testvar"].Value = testvar;

    Dts.TaskResult = (int)ScriptResults.Success;

    }

    and then added the ReadWriteVariables name in SSIS User::testvar. I execute the task and I receive no error, but I don't see the variable changing to 1. Can someone please tell me what I am missing?

    Thanks so much,

    Sharon

  • Have you stepped through the code debugging it to see what's happening? It looks like it is coded correctly.

  • Sha_ (10/2/2011)


    Hi folks,

    I'm not sure if I'm going this correctly, but I am trying to assign a variable in a script task using c#. I've added this:

    public void Main()

    {

    int testvar = 1;

    Dts.Variables["User::testvar"].Value = testvar;

    Dts.TaskResult = (int)ScriptResults.Success;

    }

    and then added the ReadWriteVariables name in SSIS User::testvar. I execute the task and I receive no error, but I don't see the variable changing to 1. Can someone please tell me what I am missing?

    Thanks so much,

    Sharon

    When do you check if the value of the variable has changed? When the package has finished running, the variable will get its original value back.

    You need to check it in the locals window while the package is running (set a breakpoint), or use a message box inside your script task.

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

  • Thank you Jack and Koen for your responses. Sorry for my delay in getting back to you, but I am only able to work on this on weekends. I should have responded sooner.

    I did set the breakpoint OnVariableChanged, and also checked in the locals window on your suggestions. The break doesn't break, and locals is blank. It doesn't appear that the variable is changing.

    When creating the script task in c#, am I supposed to be bringing in the .csproj into my local SSIS package/project in any other way? I have been assuming that it's already brought in by default if I used the script task.

    Thanks once again,

    Sharon

  • I take that back - it does work. I wasn't seeing it correctly in the locals window. It hits on the Post Execute Event.

    Thank you both so very much!

    Sharon

  • If you add a mesage box right after the

    assignment, do you see the changed value?

    Edit: glad to hear you got it working.

Viewing 6 posts - 1 through 5 (of 5 total)

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