开发者

Error handling in DTS Package execution using .NET

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;
        }
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜