C# 错误:调用目标已引发XX处的0x1:异常
我正在尝试使用SSIS中的C#任务脚本将文件从FTP服务器复制到本地驱动器。该脚本在SQL Studio 2008 R2中运行良好,但使用SQL SSDT(SQL Server数据工具)2015对2016进行了版本更新,当我第一次执行该脚本时,它运行正常,但后来抛出以下错误: 错误:0x1位于3复制并重命名EC文件:调用的目标已引发异常。任务失败:3-复制和重命名EC文件 我读了几篇文章,了解到被调查者通过添加对dll版本12.0.0的引用并将目标框架更改为.Net Framework 4.5解决了这个问题 目前我的目标框架是.NETFramework4.5 我怎样才能停止得到这个错误 在应用程序中的哪里可以找到进行更改的dll引用 谢谢你的帮助 我的C#程序如下所示:C# 错误:调用目标已引发XX处的0x1:异常,c#,sql-server,ssis,etl,script-task,C#,Sql Server,Ssis,Etl,Script Task,我正在尝试使用SSIS中的C#任务脚本将文件从FTP服务器复制到本地驱动器。该脚本在SQL Studio 2008 R2中运行良好,但使用SQL SSDT(SQL Server数据工具)2015对2016进行了版本更新,当我第一次执行该脚本时,它运行正常,但后来抛出以下错误: 错误:0x1位于3复制并重命名EC文件:调用的目标已引发异常。任务失败:3-复制和重命名EC文件 我读了几篇文章,了解到被调查者通过添加对dll版本12.0.0的引用并将目标框架更改为.Net Framework 4.5解
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块读取实际异常,因为以下异常是泛型的: 调用的目标已引发异常 请尝试使用以下代码:
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;
}
}
参考资料