gpt4 book ai didi

c# - 如何解决 "Runtime error Exception has been thrown by the target of an invocation"我是否缺少 DLL 文件?

转载 作者:行者123 更新时间:2023-11-30 18:12:38 28 4
gpt4 key购买 nike

我正在做一些测试,使用 Foreach loop ContainerExecute SQL Task 将完整的结果集输出到脚本任务(显示消息框)。但遇到 DTS 脚本任务:运行时错误。

错误消息框

Error Message Box

我是否缺少某种 DLL 文件?

脚本

Script

控制流程

Control FLow

最佳答案

错误信息

exception has been thrown by the target of an invocation

是脚本代码抛出异常时显示的一般错误消息。要阅读主要错误消息,您可以在代码中添加一个 try catch 子句并使用 Dts.FireError() 方法抛出真正的异常。

public void Main()
{
try
{
string strMessage = Dts.Variables["User::FinalTieOut"].Value.ToString();
Messagebox.Show(strMessage);
Dts.TaskResult = (int)ScriptResults.Success;

}
catch(Exception ex)
{
Dts.Events.FireError(0,"An error occured", ex.Message,String.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}

变量名

基于 Using Variables in the Script Task - official documentation :

You add existing variables to the ReadOnlyVariables and ReadWriteVariables lists in the Script Task Editor to make them available to the custom script. Keep in mind that variable names are case-sensitive. Within the script, you access variables of both types through the Variables property of the Dts object. Use the Value property to read from and write to individual variables. The Script task transparently manages locking as the script reads and modifies the values of variables.

只需将 USER::FinalTieOut 更改为 User::FinalTieOut 即可解决问题。

关于c# - 如何解决 "Runtime error Exception has been thrown by the target of an invocation"我是否缺少 DLL 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55052627/

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