SSIS C# 脚本任务 - 您能否设置 Dts.Variable - 错误:分配给变量的值的类型与当前变量类型不同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1633184/
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 C# Script task - Can you set a Dts.Variable - Error: The type of the value being assigned to variable differs from the current variable type
提问by CPU_BUSY
My variable is a string at the package level and have added it as readwritevariable example:
我的变量是包级别的字符串,并将其添加为 readwritevariable 示例:
public void Main()
{
string sServer = "localhost";
Dts.Variables["User::sourceServer"].Value = sServer;
}
will result in Error: The type of the value being assigned to variable differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
将导致错误:分配给变量的值的类型与当前变量类型不同。变量在执行期间可能不会改变类型。变量类型是严格的,Object 类型的变量除外。
采纳答案by Ryan Brunner
If you've verified that the variable is indeed a string at the package level, ensure that there are no other variables with a narrower scope that might have a different type. If you have a variable scoped to the script task, or a container that the script task is in, SSIS will use that variable instead of the package-level variable.
如果您已经在包级别验证该变量确实是一个字符串,请确保没有其他可能具有不同类型的更窄范围的变量。如果您有一个作用域为脚本任务的变量,或者脚本任务所在的容器,SSIS 将使用该变量而不是包级变量。
You can check this in the designer by clicking on the script task, and ensuring that a new variable doesn't appear in the variable toolbar.
您可以通过单击脚本任务在设计器中检查这一点,并确保新变量不会出现在变量工具栏中。