How to change the connection string in a DTS package at runtime from a .NET application?

I am trying to run a dts package from a C # application. However, I need to dynamically change the connection string. I looked on the Internet and found that I should use the Variables property of the Package object. The fact is that my Visual Studio 2010 does not show this Variables attribute for the package. Namespaces I Use

using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

What should I do?

+3
source share
1 answer

Do you really mean DTS (SQL2000) or its new SSIS? In any case, I had a similar problem when I had to specify several dynamic connections to the package. I decided that this is:

: - SQL : - "" - "" -

: - SQL- / @User:: variables - Script, →

DTS:

' Get a reference to self (the DTS package currently running)
Set oPkg = DTSGlobalVariables.Parent

' Get connection to Input File - Set Path
Set oCn = oPkg.Connections.Item ( "MasterFileIn" )
oCn.DataSource = workAreaPath & "MasterFile.txt"

SSIS , . ScriptMain.cs:

ConnectionManager cm = Dts.Connections["MasterFileIn"];
cm.ConnectionString = Dts.Variables["DataSource"].Value;
+2

All Articles