Domanda

I am writing an application that programatically imports user selected flat files into a database (with other logic, so I really have to use SSIS). I have the list of SSIS packages in a table and load the package and execute it in code. However my SSIS packages are using design time parameters to lookup their configuration in another database server (QA, in this case) rather than runtime config parameters.

How can I override the connection string to use one that I would supply in code?

Here is a sample of the source I am using

Dim app As New Microsoft.SqlServer.Dts.Runtime.Application
Dim pkg As Microsoft.SqlServer.Dts.Runtime.Package = New Microsoft.SqlServer.Dts.Runtime.Package()

pkg = app.LoadFromSqlServer(packageName, serverName, Nothing, Nothing, Nothing)

pkg(0).ConfigurationType = DTSConfigurationType.ISqlServer


Dim result = pkg.Execute
È stato utile?

Soluzione

Take a look at the source code for DTLoggedExec.

In the Program.cs file there is some code that sets property values, you can probably use this in your program.

DtsProperty p;
Variable pkgObj;
pkgObj = (Variable)package.GetObjectFromPackagePath(valuePath, out p);                                        

if (p != null && pkgObj != null)
{
Console.WriteLine(" (Parameter Type: " + pkgObj.DataType + ")");
p.SetValue(pkgObj, Convert.ChangeType(s[1], pkgObj.DataType));
}

The valuePath is the path to the object and s1 is your value you want to put into that property. For a connection manager, it usually is something like:

\Package.Connections[CONNMGRNAME].Properties[ConnectionString]

Altri suggerimenti

Your package object should expose Connections property/collection of ConnectionManager objects. You can iterate this collection to find CM You want to modify. Afterwards just set its ConnectionString property to any correct value.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top