Click here to Skip to main content
15,892,480 members

Providing environment variables to package execution using PackageInfo class

Vic91 asked:

Open original thread
I've been looking around the web for days now and I haven't been able to find a single example on how to pass environment variables to a package.

We're using the new ssis project development to deploy packages to the SSIS catalog so I need to use the Microsoft.SQLServer.Management.IntegrationServices assembly to access packages. I found an excelent example on how to run it here. The problem is, every one of our packages (more than 100) have around 7 parameters they need to execute and I can't provide values for them! Not even hard-coded values. It's driving me insane. I keep getting the Reference not made to an instance of an object error because apparently the PackageInfo class is static. For this project, there are different environments configured in the SSIS Catalog that I need to map to the variables of the packages.

I've tried setting the parameters like they set the SYNCHRONIZED parameter on the example, but to no effect. For some variables I get an error saying that I don't have sufficient permissions to access them, which makes sense but I can't figure out how (or where) to provide the needed credentials (It might be good to mention that we've used windows authentication until now, configuring permissions to the domain users that are working on the project).

I am stuck. Has anybody done this? I know its really easy to set the variables the old way (Dts.Runtime assembly) but this new assembly is poorly documented and very few examples are available on the web (none of which touch the subject of environment variables). Any help would be gratefully accepted!

[EDIT]

This is the code I'm using:

C#
SqlConnection connection = new SqlConnection(@"Data Source=my-ssis-server;Initial Catalog=MyDB;Integrated Security=SSPI;");
IntegrationServices ssis = new IntegrationServices(connection);

//Get handle on package
PackageInfo pk = ssis.Catalogs["SSISDB"].Folders["MyFolder"].Projects["MyProject"].Packages["MyPackage.dtsx"];
var executionParameter = new Collection<PackageInfo.ExecutionValueParameterSet>();

executionParameter.Add(new PackageInfo.ExecutionValueParameterSet
   {
   	   ObjectType = 50,
   	   ParameterName = "SYNCHRONIZED",
   	   ParameterValue = 1
   });

//This throws: The parameter 'MyParam' does not exist or you do not have sufficient permissions.
/*executionParameter.Add   
   (new PackageInfo.ExecutionValueParameterSet
   {
       ObjectType = 50,
       ParameterName = "MyParam",
       ParameterValue = "myvalue"
   });*/

//This throws: Object reference not set to an instance of an object.
pk.Parameters["MyParam"].Set(
   ParameterInfo.ParameterValueType.Literal,
   "MyValue"
);

pk.Alter();

long executionIdentifier = pk.Execute(false, null, executionParameter);
Tags: C#, .NET, SQL Server, SSIS

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900