using variable in SSIS


I have a question in "script task" and "script component".

(1). in "scrip task". I need use "Dts" Variables to access variable like below
 string xls_name = (string)Dts.Variables["User::strFileName"].Value;
but in "script component" I need use "this" to access variable like below

I don't understand why it need do like this way, and I would like to learn it. could someone teach me about this.

(2) in  "script component", there are different function block like PreExecute(), postExecute(), CreateNewOutputRows()...etc.

Is it possible to make global variable in one block and let other block can access it. Could you please give me a small code example. thank you

thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Reza RadConsultant, TrainerCommented:

(1) you can also use (string)Dts.Variables["User::strFileName"].Value; in script component. in fact the way of accessing variables is same.

there are builtin functions in script component ,
you can find more about what functionality they have here:

and also you can use global variable.
but let us know what you want to do, and we will help you more in details.

Megan BrooksSQL Server ConsultantCommented:
The script component is built around the ScriptComponent class, which ultimately inherits from PipelineComponent. If you were to write your own custom component assembly, you would inherit directly from PipelineComponent. It is the source of the various methods such as PreExecute, PrimeOutput, and PostExecute.

The script task makes it much easier to write a data flow component by providing various "wrappers" that do much of the work for you. As long as they were providing the other wrappers, I guess they decided to throw in a wrapper for variables as well while they were at it.

The script task executes in a very different environment outside the pipeline, and those authors took a different approach that didn't involve a variable wrapper. The underlying VariableDispenser object is available in both types of scripts, though, as an alternative to declaring variables at design time and using the Dts object or component wrapper variables.

To communicate between methods in the script component you would normally use a member variable. The example below shows something I often have needed to do -- maintain a row count.

public class ScriptMain : UserComponent
    int Rows = 0;

    //Write the summary
    public override void FinishOutputs()
        Output0Buffer.Rows = Rows;

    //Count input rows
    public override void Input0_ProcessInputRow(Input0Buffer Row)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.