使用 .NET 执行 DTS 包时的错误处理

发布于 2024-09-27 22:54:22 字数 1447 浏览 4 评论 0原文

我正在按照本文中的代码使用 C# 执行 SQL Server 2000 DTS 包 http://support.microsoft .com/kb/319985。执行包后,我将循环执行每个步骤,以查明是否有任何步骤失败,并获取有关错误的信息(如果失败)。我还使用此信息来确定软件包是否成功(如果任何步骤失败,则软件包失败)。 我在这里面临的问题是,有时包会失败(跳转到 catch 块),并显示一条通用错误消息“执行已被用户取消”,并且不会提供除此之外的更多信息。如果我使用 DTSRUNUI 手动运行该包,那么我发现该包需要一个文本文件作为输入,而该文件在指定位置不存在。在这种情况下,来自 .NET 代码的错误消息应该清楚地说明这一点。我是否需要对文章中的代码进行任何更改,以获取有关错误的更多详细信息。我添加了以下额外内容来获取错误信息,但没有多大帮助。包上有两个名为“FailonError”的属性,步骤对象上有两个名为“ExecuteInMainThread”的属性。我也尝试设置它们,但这也没有帮助。不确定是否需要它们。

    bool success = true;
if (package != null)
{
    foreach (Step step in package.Steps)
    {
        if (step.ExecutionStatus == DTSStepExecStatus.DTSStepExecStat_Completed 
            && step.ExecutionResult == DTSStepExecResult.DTSStepExecResult_Failure)
        {
            int errorCode, helpContext;
            string errorSource, errorDescription, helpFile, iDofInterfaceWithError;

            step.GetExecutionErrorInfo(out errorCode, out errorSource, out errorDescription, out helpFile,
                                       out helpContext, out iDofInterfaceWithError);
            LogToTextFile(
                string.Format(
                    "step name: {0} error Code : {1}, error Source : {2}, error Description: {3}", step.Name,
                    errorCode, errorSource, errorDescription));
            success = false;
        }
    }
}

I am executing a SQL Server 2000 DTS package using C# by following the code from this article http://support.microsoft.com/kb/319985. once the package is executed I am looping through each step to find out if any step has failed and get info about error if it has failed. I also use this information to find out if the package has succeeded or not (package failed if anyone step has failed).
the issue I am facing here is that sometimes the package fails (jumps to catch block) with a generic error message that "Execution was canceled by user" and doesn't give any more information than that. If I run the package manually using the DTSRUNUI then I found that the package was expecting a text file as an input and the file didn't exist in the specified location. in that case the error message from .NET code should say that clearly. do I need to make any changes to the code from the article, to get more details about the errors. I added the following extra to get error information, but didn't help much. there are two properties called "FailonError" on package and "ExecuteInMainThread" on step objects. I tried setting them as well, but that also didn't help. not sure if they are required.

    bool success = true;
if (package != null)
{
    foreach (Step step in package.Steps)
    {
        if (step.ExecutionStatus == DTSStepExecStatus.DTSStepExecStat_Completed 
            && step.ExecutionResult == DTSStepExecResult.DTSStepExecResult_Failure)
        {
            int errorCode, helpContext;
            string errorSource, errorDescription, helpFile, iDofInterfaceWithError;

            step.GetExecutionErrorInfo(out errorCode, out errorSource, out errorDescription, out helpFile,
                                       out helpContext, out iDofInterfaceWithError);
            LogToTextFile(
                string.Format(
                    "step name: {0} error Code : {1}, error Source : {2}, error Description: {3}", step.Name,
                    errorCode, errorSource, errorDescription));
            success = false;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风透绣罗衣 2024-10-04 22:54:22

我使用 DTSRun.EXE 执行 DTS 包(通过从 C# 启动该进程)并将其控制台输出重定向到该文件,并且该输出通常足以防止出现任何错误。

I am using DTSRun.EXE to execute the DTS package (by launching the process from C#) and redirecting its console output to the file and that output is normally sufficient in case of any errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文