gpt4 book ai didi

sql-server - SSIS 找不到变量

转载 作者:行者123 更新时间:2023-12-05 06:39:54 24 4
gpt4 key购买 nike

我想从 visual studio 解决方案中执行包

代码:

private Microsoft.SqlServer.Dts.Runtime.Package pkgPaquete;
private Application appAplicacion;

public DTSExecResult EjecucionPaquete(string str_Paquete, List < CatVariablesEtl > Vars = null) {

DTSExecResult respuesta;
try {
appAplicacion = new Application();

appAplicacion.PackagePassword = "pass";

pkgPaquete = appAplicacion.LoadPackage(str_Paquete, null);
foreach(CatVariablesEtl item in Vars) {
pkgPaquete.Variables[item.str_NombreVariable.ToString()].Value = item.str_ValorVariable.ToString();
}

respuesta = pkgPaquete.Execute();

return respuesta;
} catch (Exception ex) {

throw new NotImplementedException();
}

}
}
}

它在抛出 catch 的这一行停止到 foreach 语句:

pkgPaquete.Variables[item.str_NombreVariable.ToString()].Value = item.str_ValorVariable.ToString();

enter image description here

str_NombredeVariable 值: enter image description here

item.str_ValorVariable 值: enter image description here

参数包:

enter image description here

错误:

The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created.

我阅读了其他相关问题,但没有找到我的问题的正确答案。非常感谢帮助。问候

更新:作为我尝试使用的哈迪评论

var setValueParameters = new Collection<PackageInfo.ExecutionValueParameterSet>();

但我只是得到 vs 红色标记,我需要导入一些引用吗? enter image description here

作为 Hadi 的第二个答案,我无法引用 pkgPaquete.Variables: enter image description here

最佳答案

第一次尝试

尝试从变量名中删除 User::

foreach(CatVariablesEtl item in Vars) {
pkgPaquete.Variables[item.str_NombreVariable.ToString().Replace("User::","")].Value = item.str_ValorVariable.ToString();
}

第二种赋值方法

也可以试试用这个方法给变量赋值:

Microsoft.SqlServer.Dts.RunTime.Variables myVars = pkgPaquete.Variables;

foreach(CatVariablesEtl item in Vars) {
myVars[item.str_NombreVariable.ToString().Replace("User::","")].Value = item.str_ValorVariable.ToString();
}

Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = pkgPaquete.Execute(null, myVars, null, null, null);

如果使用参数,看起来它们不能以编程方式修改。尝试使用变量代替它们

关于sql-server - SSIS 找不到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44190396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com