将值从 C# 传递给 SSIS 连接字符串 [英] Passing values to SSIS Connecting string from c#

查看:34
本文介绍了将值从 C# 传递给 SSIS 连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS 2008/SQL 2008

VS 2008 / SQL 2008

我正在将 .csv 文件导入 SQL 表.

I am importing .csv file to SQL Table.

我想从 C# 代码动态传递源文件和目标连接字符串.

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

由于某些原因,这段代码运行良好,但包没有执行!!!!我应该如何将连接字符串从 C# 代码动态传递给 SSIS 包!!

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();

推荐答案

动态更改连接字符串的最佳方法是从包中检索所需的连接,然后更改其连接字符串.这与使用连接信息设置变量不同.在这种情况下,您需要使用:

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;

其中 sConndConn 是包中连接的名称.

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

这篇关于将值从 C# 传递给 SSIS 连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆