Tuesday, November 2, 2010

Passing parameters to SSIS package from command prompt

TestParamPackage.dtsx is a simple package having two string variables defined in it. An script task is added in the control flow just to use these variables.

The two variables are FirstName & LastName. Following code is added to the script task -

MessageBox.Show(Dts.Variables["FirstName"].Value.ToString() + Dts.Variables["LastName"].Value.ToString());

Let's assume the package is at the location - "c:\TestParamPackage.dtsx"

Now run the below command in the command prompt and execute it -

C:\>dtexec /f "c:\TestParamPackage.dtsx" /set \Package.Variables[User::FirstName].Value;"Santosh"

A message box will pop up showing text as "Santosh"

Now run the below command -

C:\>dtexec /f "c:\TestParamPackage.dtsx" /set \Package.Variables[User::FirstName].Value;"Santosh" /set \package.variables[User::LastName].Value;"Joshi"

If you notice, I have passed two parmeters form the command prompt. In Message box now SantoshJoshi will appear.

N.B. After the "Value;" don't put any space else it will through error.