错误:XX处为0x1:调用目标已抛出异常 [英] Error: 0x1 at XX: Exception has been thrown by the target of an invocation

查看:248
本文介绍了错误:XX处为0x1:调用目标已抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SSIS中的C#任务脚本将文件从FTP服务器复制到本地驱动器.该脚本在SQL Studio 2008 R2中运行良好,但是使用SQL SSDT(SQL Server数据工具)2015进行了2016年版本更新,当我第一次执行该脚本时,它运行正常,但随后引发以下错误:

I am trying to copy files from an FTP server to a local drive using C# Task script in SSIS. The script ran well in SQL Studio 2008 R2, but there was a version update to 2016 using SQL SSDT (SQL Server Data Tools) 2015, and when I first executed the script it ran OK, but later threw the following error:

错误:3复制并重命名EC文件时为0x1:调用的目标引发了异常.任务失败:3-复制并重命名EC文件

Error: 0x1 at 3-Copy and rename EC Files: Exception has been thrown by the target of an invocation. Task failed: 3-Copy and rename EC Files

我阅读了几篇文章,并了解到响应者通过添加对dll版本12.0.0的引用来解决此问题,并将Target Framework更改为.Net Framework 4.5.

I read a few post, and learned that the respondent fixed the problem by adding reference to dll version 12.0.0 and changed Target Framework to .Net Framework 4.5.

当前我的目标框架是.Net Framework 4.5.

Currently my Target Framework is .Net Framework 4.5.

如何停止收到此错误?

How can I stop getting this error?

我在应用程序的哪里可以找到dll引用来进行更改?

Where in application would I find the dll reference to do that change?

感谢您的帮助.

我的C#程序如下所示:

My C# program is shown below:

using System; 
using System.IO;

namespace ST_d70bfcb8d94b40849d1d525fe3731f14.csproj
{
    [Microsoft.SqlServer

.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion


public void Main()

    {
        string fileDate = string.Format("{0:d4}", DateTime.Today.Year).ToString() + string.Format("{0:d2}", DateTime.Today.Month).ToString() + "13";
        string src1FileName = @"\\Slocation03\Reports\SSI224-069_" + fileDate + ".txt";
        string des1FileName = @"\\Slocation03\Reports\EContacts\SSI224-069.txt";

        string src2FileName = @"\\Slocation03\Reports\SSI224-071_" + fileDate + ".txt";
        string des2FileName = @"\\Slocation03\Reports\EContacts\SSI224-071.txt";

        if (File.Exists(src1FileName))
        {
            File.Copy(src1FileName, des1FileName, true);
        }

        if (File.Exists(src2FileName))
        {
            File.Copy(src2FileName, des2FileName, true);
        }

        Dts.TaskResult = (int)ScriptResults.Success;
    }
}

}

推荐答案

该错误可能是由于从UNC路径读取或写入本地文件的权限问题引起的,请尝试添加try ... catch块以读取真实内容异常,因为以下异常是通用的:

The Error may be cause by a permission issue for reading from UNC path or writing to local file, try adding a try ... catch block to read the real exception since the following exception is generic:

调用的目标抛出了异常

Exception has been thrown by the target of an invocation

尝试使用以下代码:

public void Main()

{
try{

        string fileDate = string.Format("{0:d4}", DateTime.Today.Year).ToString() + string.Format("{0:d2}", DateTime.Today.Month).ToString() + "13";
        string src1FileName = @"\\Slocation03\Reports\SSI224-069_" + fileDate + ".txt";
        string des1FileName = @"\\Slocation03\Reports\EContacts\SSI224-069.txt";

        string src2FileName = @"\\Slocation03\Reports\SSI224-071_" + fileDate + ".txt";
        string des2FileName = @"\\Slocation03\Reports\EContacts\SSI224-071.txt";

        if (File.Exists(src1FileName))
       {
                File.Copy(src1FileName, des1FileName, true);
        }

       if (File.Exists(src2FileName))
        {
            File.Copy(src2FileName, des2FileName, true);
        }

        Dts.TaskResult = (int)ScriptResults.Success;

    }catch(Exception ex){

        Dts.FireError(0,"An error occured", ex.Message,String.Empty, 0);
        Dts.TaskResult = (int)ScriptResult.Failure;

    }

}

参考

  • SSIS - Script Task error: Exception has been thrown by the target of an invocation
  • Copy Files from UNC to Local Drive

这篇关于错误:XX处为0x1:调用目标已抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆