I have an SSIS package which has some Project.params set.
How do I pass values for those parameters to the SSIS package via C#?
I'm trying the following:
const string pkgLocation = @"export.dtsx";
var app = new Application();
var pkg = app.LoadPackage(pkgLocation, null);
var results = pkg.Execute();
This returns a failure, with Errors collection containing "The variable "$Project::connString" was not found in the Variables collection. The variable might not exist in the correct scope."
So I tried adding
var param = pkg.Parameters.Add("connString", TypeCode.String);
param.Value = "test";
var results = pkg.Execute();
But this throws a DtsGenericException.
I believe you will need to utilize the ParameterValue class.
The report service will have a method:
I am assuming you are loading the report, "export.dtsx", into SSIS and executing via the report service.
I think I got it. The trick is to deserialize your ispac file (VS builds this but you can do it via msbuild) into a
Project
object. The Project object allows us to set project level parameters (as well as access project level connection managers).From there we will need to get a reference to the specific package we want but it will be a
PackageItem
. PackageItems can't run but they do have a Package property we will use to instantiate thePackage
class which does have anExecute
methodThis assumes you have an SSIS project called
so_31812951
which compiled to an ispac located at C:\sandbox\so_31812951\so_31812951\bin\Development\so_31812951.ispac This project has a single package called Package.dtsx. There will be a Project level parameter, Int32, namedProjectParameter
as well as a package level parameter, Int32, namedPackageParam