Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

sql server 2008 - Passing values to SSIS Connecting string from c#

VS 2008 / SQL 2008

I am importing .csv file to SQL Table.

I want to pass dynamically the Source File and Destination Connection string from C# Code.

For some reasons, this code is working well but package is not executing !!!! How should i pass connection string dynamically from C# code to SSIS Package !!

string strSourceConn = Server.MapPath(filePlacedOrder.Value);
string strDestConn = System.Configuration.ConfigurationManager.AppSettings["SDB"];
string pkgLocation = Server.MapPath("Package.dtsx");

Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;

app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, null);

pkg.Variables["sConn"].Value = strSourceConn;
pkg.Variables["dConn"].Value = strDestConn;

pkgResults = pkg.Execute();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The best way to dynamically change the connection string is to retrieve the desired connection from the package and then change its connection string. This is different from setting variables with the connection information. In this case you would want to use:

pkg.Connections["sConn"].ConnectionString = strSourceConn;
pkg.Connection["dConn"].ConnectionString = strDestConn;

Where sConn and dConn are the names of the connections in your package.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...