Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to Programmatically modify the connection string of a Flat File Source component using SSIS in c#. A source Destination Mapping was set in SSIS. But I tried updating the connection string of the source to modify the connection manager of the source for the statically created package. The source mapping is not getting updated.

What I have tried:

Code as below:
string strSourceConn = @"D:\SSIS\Test3\emp.txt";
          // Create a new SSIS Package

          //Package package;
          Microsoft.SqlServer.Dts.Runtime.Application app;

          string pkgLocation = @"D:\SSIS\Test3\Integration Services Project2\Integration Services Project2\Package.dtsx";

          app = new Microsoft.SqlServer.Dts.Runtime.Application();
          package = app.LoadPackage(pkgLocation, null);
          // Add a Connection Manager to the Package, of type, FLATFILE
          var connMgrFlatFile = package.Connections.Add("FLATFILE");

          connMgrFlatFile.ConnectionString = strSourceConn;
          connMgrFlatFile.Name = "My Import File Connection";
          connMgrFlatFile.Description = "Flat File Connection";

          package.Execute();
Posted
Updated 3-Apr-18 3:21am
v2
Comments
[no name] 3-Apr-18 19:19pm    
This is not clear much please elaborate
ranio 4-Apr-18 0:59am    
I have set a source destination mapping in SSIS. I am setting source to a flat file component(text file contents) read and mapped to Sql DB and insertion is being done accordingly. I want to change the flat file Source connection string alone dynamically and save to destination mapped. Set flat file Source connection string is not getting updated.

Mapped Source Path Connection String:
string strSourceConn = @"D:\SSIS\Test3\empdetails.txt";

Source path Connection String:

string strSourceConn = @"D:\SSIS\Test3\emp.txt";
// Create a new SSIS Package

//Package package;
Microsoft.SqlServer.Dts.Runtime.Application app;

string pkgLocation = @"D:\SSIS\Test3\Integration Services Project2\Integration Services Project2\Package.dtsx";

app = new Microsoft.SqlServer.Dts.Runtime.Application();
package = app.LoadPackage(pkgLocation, null);
// Add a Connection Manager to the Package, of type, FLATFILE
var connMgrFlatFile = package.Connections.Add("FLATFILE");

connMgrFlatFile.ConnectionString = strSourceConn;
connMgrFlatFile.Name = "My Import File Connection";
connMgrFlatFile.Description = "Flat File Connection";

package.Execute();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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