C# SSIS 在脚本任务中显示变量值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17990992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SSIS display variable values in script task
提问by jhowe
I'm doing some testing, outputting a full result set from a Execute SQL Task into a Foreach loop as below
我正在做一些测试,将执行 SQL 任务的完整结果集输出到 Foreach 循环中,如下所示
and I just want to output my variable values to a message box, however it doesn't seem to work.
我只想将我的变量值输出到一个消息框,但它似乎不起作用。
public void Main()
{
try
{
// TODO: Add your code here
string Variables = Dts.Variables["User::ClientID"].ToString() +
Dts.Variables["User::Passphrase"].ToString() +
Dts.Variables["User::KeyFileName"].ToString() +
Dts.Variables["User::InboundEncryptionRequired"].ToString() +
Dts.Variables["User::SftpResponseRequired"].ToString() +
Dts.Variables["User::OutboundDecryptionRequired"].ToString() +
Dts.Variables["User::SftpHost"].ToString() +
Dts.Variables["User::SftpPort"].ToString() +
Dts.Variables["User::SftpUserName"].ToString() +
Dts.Variables["User::Active"].ToString() +
Dts.Variables["User::SftpDownloadFrom"].ToString() +
Dts.Variables["User::SftpUploadTo"].ToString() +
Dts.Variables["User::SftpDeleteFilesFromRemote"].ToString() +
Dts.Variables["User::ConnectionProtocol"].ToString();
MessageBox.Show(Variables);
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
}
}
I'm just getting "element cannot be found in a collection" or something, even though I know the query is outputting 2 rows.
我只是收到“在集合中找不到元素”之类的信息,即使我知道查询正在输出 2 行。
I have also mapped my variables on the foreach loop and specified read only variables on scrip task.
我还在 foreach 循环上映射了我的变量,并在脚本任务上指定了只读变量。
* UPDATE *
* 更新 *
This is driving me nuts. I've triple checked my variable names, can confirm I'm getting full result set.
这让我发疯。我已经三重检查了我的变量名,可以确认我得到了完整的结果集。
I removed the User:: from my script task variables, but still no luck.
我从脚本任务变量中删除了 User::,但仍然没有运气。
采纳答案by Fernando
It sounds as if one of your variable names is not spelled correctly and it cannot be found in the array.
听起来好像您的变量名称之一拼写不正确,并且在数组中找不到它。
Also you could use
你也可以使用
string Variables = String.Format("{0},{1},...",Dts.Variables["User::ClientID"],Dts.Variables["User::Passphrase"],...)
to display the values or set your variables string.
显示值或设置变量字符串。
回答by makciook
You don't have to specify the scope: User
or System
. Remove User::
from each name. If it still doesn't work - you must have misspelled one of the names.
您不必指定范围:User
或System
。User::
从每个名称中删除。如果它仍然不起作用 - 您一定拼错了其中一个名称。
Also you need to get the value and convert it to string. Correct format is:
Dts.Variables["Passphrase"].Value.ToString()
您还需要获取值并将其转换为字符串。正确格式为:
Dts.Variables["Passphrase"].Value.ToString()
回答by user3010305
You have to pass in the variables you are using. Double-click the Script Task and in the "Script Task Editor" modal window, enter the variables you want to display in "ReadOnlyVariables" or "ReadWriteVariables". Then you'll be able to reference them in your code.
您必须传入正在使用的变量。双击脚本任务并在“脚本任务编辑器”模式窗口中,在“ReadOnlyVariables”或“ReadWriteVariables”中输入要显示的变量。然后你就可以在你的代码中引用它们。
回答by CalumH
I just stumbled upon this after trying to solve a similar problem. The first issue I found with your code is that you don't have
在尝试解决类似问题后,我偶然发现了这一点。我在您的代码中发现的第一个问题是您没有
.value
。价值
before the .ToString in the string you are concatenating. I changed this on mine and it worked.
在要连接的字符串中的 .ToString 之前。我改变了我的,它奏效了。