SSIS Use DataFlow task with variables instead of a source database

11,791

In your dataflow choose a Script Component.

When prompted to choose Source, Destination, or Transformation, choose Source.

Add your pre populated variables to the CustomProperties.ReadOnlyVariables section of the script tab.

Go to the Inputs and Outputs section.

Add a column to the default output for each of your variables.

In your script (if using C#) put something similar to the following in the CreateNewOutputRows() section

    Output0Buffer.AddRow();
    Output0Buffer.ContainerName = Variables.ContainerName;
    Output0Buffer.TaskName = Variables.TaskName;
    Output0Buffer.TaskStartDate = Variables.ContainerStartTime;

Save your script.

Connect your script component to your destination object.

Share:
11,791
AlpineCoder
Author by

AlpineCoder

Updated on June 14, 2022

Comments

  • AlpineCoder
    AlpineCoder almost 2 years

    I have a task that I am working on that has me stumped. Hoping you can help me. I am using a data flow task which is basically inserting a row into a sqlite table. I was doing this using a "SQL Task" but unfortunately the only way to successfully insert a guid into the sqlite table is to convert it as a byte stream using the data flow task. I do not want to use a source database because my data is not flowing from one table to another. I really just want to take my populated variables and convert them to a byte stream which i can then insert successfully into a sqlite database. The issue is, i cannot use a dataflow task without a source database.

    My work-around so far has been to declare a source database/table and only one column (but never use it in the data flow). This works fine and I am unable to insert the row into sqlite using my pre-set variables, but i am left with a somewhat annoying message in my Output log every time i do this:

    Warning: 0x80047076 at , SSIS.Pipeline: The output column "" (117) on output "OLE DB Source Output" (11) and component "OLE DB Source" (1) is not subsequently used in the Data Flow task. Removing this unused output column can increase Data Flow task performance.

    Anyone know of a good way to get this warning not to show up?

  • AlpineCoder
    AlpineCoder over 11 years
    Thanks William. I was not aware that the script component could be used as a source. I figured only the Data Flow Sources were my available options.
  • codeputer
    codeputer almost 10 years
    This worked great for me the first time through, but subsequent executions (Data Flow task within a ForEach), the variables are not changing! I have them as Readonly in this script, but in the previous script they are ReadWrite. Changing them to ReadWrite fails the script component. Can this technique be used repeatedly?
  • codeputer
    codeputer almost 10 years
    DISREGARD previous comment - I'm a NOB, as I had an expression in a variable that was returning a static value...