【发布时间】:2021-04-05 04:21:50
【问题描述】:
我在尝试在 SSIS 中执行我的 SCRIPT TASK 时收到此错误消息(我使用的是 VS 2019 和 C#)。
试了一段时间好像不行。
错误消息:异常已被一个目标抛出 调用
详情:
in System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
in System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
in System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
in System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
in Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
这是我的代码:
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Linq;
using WinSCP;
#endregion
namespace ST_2cfb1a0997cf7b332da4453v3g1132g
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "xxxxxxxxxxxxxxxxxxxxxxxxx",
UserName = "xxxxxxxxxxxxxxxxxxxxxxxxx",
Password = "xxxxxxxxxxxxxxxxxxxxxxxxx",
};
using (Session session = new Session())
{
session.Open(sessionOptions);
const string externalPath = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const string PathLocal = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
RemoteDirectoryInfo directoryInfo = session.ListDirectory(externalPath);
RemoteFileInfo latest =
directoryInfo.Files
.Where(file => !file.IsDirectory)
.OrderByDescending(file => file.LastWriteTime)
.FirstOrDefault();
if (latest == null)
{
throw new Exception("Error, not found");
}
session.GetFiles(
externalPath.EscapeFileMask(latest.FullName), PathLocal).Check();
}
}
#region ScriptResults declaration
/// <summary>
/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
///
/// This code was generated automatically.
/// </summary>
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
这里发生了什么?
我做错了吗?
【问题讨论】:
标签: c# ssis sftp winscp winscp-net