3

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

2 Answers 2

3

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]
Sign up to request clarification or add additional context in comments.

3 Comments

I believe that this will work even if the design-time parameters are set. The problem stil may crop up if the conn string is being set later by an expression. In that case, you can change the value of the expression using similar code.
Thanks a lot N West. I finally overrode the parameters successfully following your suggestion.
Ten years later: I think you cannot alter the connection string value from loaded package. I had to clear the connection string to be able to alter it.
1

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.

2 Comments

Oh, and remember that this value (as any other) can only be changed from code before You run Execute on package object. What @NWest had said still applies though: if You have an in package expression set on this particular ConnestionManager.ConnectionString its calculated value will take precedence before the one You have set from code.
Thanks White_Raven. This is the issue that I have been dealing with, where the values for the parameters that I set in code were overridden by design time values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.