从 C# 将值传递到 SSIS 连接字符串
VS 2008 / SQL 2008
我正在将 .csv 文件导入 SQL 表。
我想从 C# 代码动态传递源文件和目标连接字符串。
由于某些原因,此代码运行良好,但包未执行!!!!我应该如何将连接字符串从 C# 代码动态传递到 SSIS 包!
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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
动态更改连接字符串的最佳方法是从包中检索所需的连接,然后更改其连接字符串。这与使用连接信息设置变量不同。在这种情况下,您需要使用:
其中
sConn
和dConn
是包中连接的名称。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:
Where
sConn
anddConn
are the names of the connections in your package.