简体   繁体   English

通过SQL Server代理在SSIS包中运行的C#脚本有时会触发调用目标抛出的异常

[英]C# script run in SSIS package through SQL Server Agent sometimes triggers Exception has been thrown by the target of an invocation

What I know: A third party software runs in the background on Java. 我所知道的:第三方软件在Java的后台运行。 I have no control of the code in this software. 我无法控制该软件中的代码。 Its job is to fetch new zip-files from an external server as soon as they are available. 它的工作是在外部服务器可用时立即从中获取新的zip文件。 These files are supposed to come in before 0100, but the third party is not able to comply to this request. 这些文件应该在0100之前进入,但第三方无法遵守此请求。 At 0100, the task I am in control over (a C# script) runs to unzip the files that have been downloaded, extract the necessary files, and zip the files we want back into a different location, and delete anything unnecessary. 在0100, 控制的任务(一个C#脚本)运行以解压缩已下载的文件,提取必要的文件,并将我们想要的文件压缩回不同的位置,并删除任何不必要的内容。 This program is set to run for 1 hour and take any files that already are there, as well as any file that appears in the folder during that hour. 此程序设置为运行1小时并获取已存在的任何文件,以及该小时内文件夹中显示的任何文件。 This program compiles fine, runs fine in Visual Studio, and is usually successfully run to completion through SQL Server Agent. 这个程序编译很好,在Visual Studio中运行良好,并且通常通过SQL Server代理成功运行完成。

Sometimes though, (like 1-2 out of 5 times), it fails with the subtle message "Exception has been thrown by the target of an invocation". 有时虽然(例如,5次中的1-2次),但它会失败,并带有微妙的消息“调用目标已抛出异常”。

What I theorise: The zip-files from the third party are quite small. 我的理论:来自第三方的zip文件非常小。 On average maybe 80-90KB. 平均可能80-90KB。 They are usually downloaded in less than a second. 它们通常在不到一秒钟内下载。 Me and my colleagues however suspect that the server, which is SSD-based, is quick enough that while the program we have made runs to unpack anything in the target folder, sometimes it picks up a zip-file that is currently, however briefly, "occupied" by the third party downloader, or even unfinished. 然而,我和我的同事怀疑基于SSD的服务器足够快,以至于我们制作的程序运行以解压缩目标文件夹中的任何内容,有时它会选择一个当前的zip文件,无论如何简单,由第三方下载者“占领”,甚至未完成。 This results in our program crashing because it cannot access the zip-file. 这导致我们的程序崩溃,因为它无法访问zip文件。

(I will not bother pasting code here because since this program normally runs fine I cannot see the code being be the problem). (我不会在这里粘贴代码,因为因为这个程序通常运行良好我看不到代码是问题)。

One of the reasons I think this could be the case is that the task is set to retry one time if it fails. 我认为可能是这种情况的原因之一是该任务设置为如果失败则重试一次。 Sometimes it runs to completion on the retry, other times it runs for anything between 10 seconds to 20 minutes before it crashes again. 有时它会在重试时运行完成,有时它会在10秒到20分钟之间运行,然后再次崩溃。 Because a second job is set to start later that night, we cannot set this task to re-run several times upon failure. 由于第二个作业设置为在当晚晚些时候开始,因此我们无法将此任务设置为在失败时重新运行多次。

The best solution would be to alter the third party program to pause during certain hours, but we have no access to make these kinds of alterations to this program. 最好的解决方案是改变第三方程序在某些时间暂停,但我们无法对此程序进行这些改动。 We are also unsure of what would happen if we were to set a scheduled task to kill this process at 0100. If this program were currently downloading a zip-file, we risk this file being corrupted, which would only result in our unpacking task failing again. 我们也不确定如果我们在0100设置一个计划任务来终止这个进程会发生什么。如果这个程序当前正在下载一个zip文件,我们冒这个文件被破坏的风险,这只会导致我们的解包任务失败再次。

A second solution we have considered is adding a try-catch clause in our program to catch this exception where we make the program wait 1 or 2 seconds, and then retry. 我们考虑的第二个解决方案是在程序中添加try-catch子句以捕获此异常,我们使程序等待1或2秒,然后重试。 The problem there is that we cannot seem to find the specific exception type that is cast. 问题是我们似乎找不到强制转换的特定异常类型。 For all I know there may not be one. 据我所知,可能没有一个。 The only way I see this could be done would be to make a generic catch-any-exception clause, where a retry is cast internally. 我认为可以做到的唯一方法是制作一个通用的catch-any-exception子句,其中重试是在内部进行的。 This would however mean that in the few cases where corrupt zip-files arrive, then we would only see an infinite loop going on. 然而,这意味着在少数损坏的zip文件到达的情况下,我们只会看到无限循环。

What I'm asking: - Does anyone know what specific exception is being cast by this kind of problem? 我在问什么: - 有谁知道这类问题正在引发什么特定的例外? (If any). (如果有的话)。 - Any reason why the try-catch-wait(1) approach is a really bad approach? - 为什么try-catch-wait(1)方法是一种非常糟糕的方法?

除了你已经做过的事情之外,没有其他人能够比你更了解你的异常,最好的方法是使用Try-Catch并创建更强大的错误处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用的目标已引发异常(SSIS & WinSCP & C#) - Exception has been thrown by the target of an invocation (SSIS & WinSCP & C#) 调用的目标已引发异常 - SSIS 脚本任务错误 - Exception has been thrown by the target of an invocation - SSIS Script Task Error C#中的调用目标已引发异常 - Exception has been thrown by the target of an invocation in C# 目标调用引发了C#异常 - C# Exception has been thrown by the target of an invocation C#WPF中的调用目标已引发异常 - Exception has been thrown by the target of an invocation in C# WPF SSIS:调用目标已抛出错误异常 - SSIS: Error Exception has been thrown by the target of an invocation SSIS 脚本任务 Excel 连接打开:调用目标抛出异常 - SSIS Script Task Excel connection open: Exception has been thrown by the target of an invocation 在 SSIS 中的 C# 脚本中抛出异常 - Exception has been thrown in C# Script in SSIS SSIS 脚本任务获取“调用目标已抛出异常”。 使用第 3 方 dll 运行时 - SSIS Script Task getting "Exception has been thrown by the target of an invocation." when running with 3rd party dll LINQ和Exception已被调用目标抛出 - LINQ and Exception has been thrown by the target of an invocation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM