简体   繁体   中英

Pass Variables to SSIS package C#

I am wanting to pass a couple of Variables into my SSIS package when calling it but I can't seem to get the correct syntax for it to work.

Microsoft.SqlServer.Dts.Runtime.Wrapper.Application app = new Microsoft.SqlServer.Dts.Runtime.Wrapper.Application();

Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSPackage100 pkg = app.LoadPackage(pkgLocation, false, null);

So the above bits work but when I go to add a variable it does not work:

pkg.Variables["mode"].Value = "test";

The error I am getting:

'IDTSPackage100' does not contain a definition for 'Variables' and no extension method 'Variables' accepting a first argument of type 'IDTSPackage100' could be found (are you missing a using directive or an assembly reference?)'

Ben,

Any reason why you are using the wrapper assemblies? IDTSPackage100 interface does not contain the Variables property. But the Package class found in the Microsoft.SqlServer.Dts.Runtime namespace contains the Variables property.

So use the Application and Package classes from the Microsoft.SqlServer.Dts.Runtime namespace (found in the Microsoft.SqlServer.ManagedDTS assembly) instead of the wrapper namespace/assembly and you should be able to access the Variables property.

Update: If you still want to use the wrapper namespace, you can cast the IDTSPackage100 object to the IDTSContainer100 object and then access the Variables from there.

IDTSContainer100 container = (IDTSContainer100)pkg;
container.Variables["User::mode"].Value = "test";

Update 2: The call on Execute method would then look like this:

pkg.Execute(null, container.Variables, null, null, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM