Tuesday, March 14, 2017

SSIS and VS 2013: using variables in the Script Task

While trying to use a Project Level Connection Managers in the new SSIS 2016, I realized we need a way to use the connection strings in the package, but didn't have access to them. So I put the Connection Strings into the variables and reuse this further on in the package.

In order to do this, I created two variables (in fact they were created before, this was a migration to SSIS 2016), I created a script task at the beginning of the package,  select the variables that I want to set as ReadWriteVariables,

edit the script and set , in the main function:
Dts.Variables["myVariable1"].Value = Dts.Connections["myConnectionManager1"].ConnectionString;Dts.Variables["myVariable2"].Value = Dts.Connections["myConnectionManager2"].ConnectionString;

That's it!

No comments: