使用 .NET 执行 DTS 包时的错误处理
我正在按照本文中的代码使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 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.