Sha*_*eal 9 c# sftp ssis winscp visual-studio-2012
使用nuget安装程序安装WinSCP .net.
Visual Studio 2013
SSIS BIDS 2012
项目引用是正确的 - 指向已安装的DLL
Project包含一个脚本,该脚本是winscp站点的示例代码的精简版本.尝试实例化SessionOptions对象的第一行失败.如果我删除SessionOptions对象,那很好.
在GAC中按照说明注册winscpnet.dll.
在visual studio ssis调试器中启动脚本,得到这个:
在System.RevlectionMethodHandle.InvokeMethod(Object target,Object [] arguments,Signature sig,Boolean constructor)at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object [] parameters,Object [] arguments)at System.Reflection.RuntimeMethodInfo.
System.RuntimeType.InvokeMember(String name,BindingFlags bindingFlags,Binder binder,Object target,Object [] providedArgs,ParameterModifier [] modifiers,CultureInfo culture ,Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化),String [] namedParams)在Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
public void Main()
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
// To setup these variables, go to SSIS > Variables.
// To make them accessible from the script task, in the context menu of the task,
// choose Edit. On the Script task editor on Script page, select ReadOnlyVariables,
// and tick the below properties.
HostName = "",
UserName = "",
Password = "",
SshHostKeyFingerprint = ""
};
bool fireAgain = false;
Dts.Events.FireInformation(0, null,
string.Format("Upload of succeeded"),
null, 0, ref fireAgain);
Dts.TaskResult = (int)DTSExecResult.Success;
}
Run Code Online (Sandbox Code Playgroud)
添加流程和流程的屏幕提示

更新:修改代码如下...完全相同的结果
public void Main()
{
bool fireAgain = false;
try
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
// To setup these variables, go to SSIS > Variables.
// To make them accessible from the script task, in the context menu of the task,
// choose Edit. On the Script task editor on Script page, select ReadOnlyVariables,
// and tick the below properties.
HostName = "",
UserName = "",
Password = "",
SshHostKeyFingerprint = ""
};
}
catch (Exception ex)
{
Dts.Events.FireInformation(0, null,
ex.InnerException.Message,
null, 0, ref fireAgain);
}
Dts.TaskResult = (int)DTSExecResult.Success;
}
Run Code Online (Sandbox Code Playgroud)
小智 13
在SSIS脚本任务中使用第三方DLL时,我们需要执行GAC.
请打开命令提示符.
cd "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools"
运行以下命令.
gacutil -i <"Path of WinSCP DLL">
运行GAC命令后,Scrip任务应按预期运行.在运行时SSIS无法获取DLL引用,这是导致此错误的原因.
希望这个有效!!
| 归档时间: |
|
| 查看次数: |
14210 次 |
| 最近记录: |