从SQL Server代理运行时,引用WinSCPnet.dll的SSIS C#2012脚本任务失败,并且“调用的目标已引发异常". [英] SSIS C# 2012 Script Task referring WinSCPnet.dll fails when run from SQL Server Agent with "Exception has been thrown by the target of an invocation"

查看:338
本文介绍了从SQL Server代理运行时,引用WinSCPnet.dll的SSIS C#2012脚本任务失败,并且“调用的目标已引发异常".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SSIS包(在VS 2013中创建),其中包含C#2012脚本任务.

I have an SSIS package (created in VS 2013) that contains a C# 2012 Script Task.

脚本任务的工作是使用WinSCP .NET程序集从SFTP服务器下载文件并将其放置在我的服务器上(带有SQL Server 2014的Windows Server 2012 R2)

The job of the script task is to download a file from an SFTP server using WinSCP .NET assembly and place it on my server (Windows Server 2012 R2 with SQL Server 2014)

我的软件包在Dev计算机上运行时,我的软件包运行良好,但是当我将其部署到服务器时,该软件包在此任务中失败,并显示错误消息

My package runs fine when I run it on my Dev machine, but when I deploy to the server my package fails at this task with the error message

调用的目标抛出了异常

Exception has been thrown by the target of an invocation

我已经进行了一些挖掘,看起来它与对WinSCPnet.dll的引用有关.

I've done some digging and it looks like it has something to do with the reference to WinSCPnet.dll.

推荐答案

上引用WinSCP文章由调用目标抛出:

这只是一个高级例外.根本原因通常存储在 InnerException .

如果在SSIS中遇到此异常,则可以使用trycatch块捕获错误,如

If you are getting this exception in SSIS, you can use trycatch block to capture the error, as show in the example for using WinSCP .NET Assembly from SSIS.

如果无法轻松访问内部异常,请检查WinSCP会话日志并调试日志文件( Session.SessionLogPath Session.DebugLogPath ).如果尚未创建这些文件,则根本原因可能是加载了WinSCPnet.dll程序集.请参见无法加载文件或程序集'file:///…\ WinSCPnet.dll'或其依赖项之一.系统找不到指定的文件..

If you cannot access the inner exception easily, inspect WinSCP session log and debug log file (Session.SessionLogPath, Session.DebugLogPath). If those file are not even created, the root cause can be loading of WinSCPnet.dll assembly. See Could not load file or assembly ‘file:///…\WinSCPnet.dll’ or one of its dependencies. The system cannot find the file specified..


从以下位置使用WinSCP .NET程序集"的安装部分中介绍了安装程序集以允许其加载. SQL Server集成服务(SSIS):

安装

首先,您需要安装 WinSCP .NET程序集.不要使用NuGet软件包. 1

Installing

First, you need to install the WinSCP .NET assembly. Do not use the NuGet package.1

您还需要将程序集安装到GAC 订阅AppDomain.AssemblyResolve事件以允许加载程序集.

You also need to install the assembly to the GAC or subscribe AppDomain.AssemblyResolve event to allow loading the assembly.


安装WinCC .NET程序集的安装说明的GAC部分"中介绍了GAC的安装. :

安装到GAC

在特殊情况下,您可能需要将程序集安装到全局程序集缓存(GAC)中,尤其是要从将程序集安装到GAC时,需要配置WinSCP可执行文件的路径.

When you install the assembly to GAC, you need to configure a path to WinSCP executable.

在开发计算机上

要将程序集安装到开发计算机上的GAC中,即具有已安装Windows SDK ,请使用以下命令:

To install the assembly into GAC on development machine, i.e. the one that has Windows SDK installed, use following command:

gacutil.exe /i WinSCPnet.dll

Windows SDK随Microsoft Visual Studio一起提供.您也可以单独安装.

Windows SDK comes with Microsoft Visual Studio. You can also install it separately.

为您的.NET Framework版本使用正确的gacutil.exe:

Use correct gacutil.exe for your version of .NET framework:

  • 对于.NET Framework 4.0或更高版本,请使用Windows SDK 7.1(或更高版本)中的gacutil:
    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1\bin\gacutil.exe;
  • 对于.NET Framework 3.5,请使用Windows SDK 6.0中的gacutil:
    C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe
  • For .NET framework 4.0 or newer, use gacutil from Windows SDK 7.1 (or newer):
    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1\bin\gacutil.exe;
  • For .NET framework 3.5, use gacutil from Windows SDK 6.0:
    C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe

在生产或用户计算机上

要将程序集安装到生产或用户计算机上的GAC中,您可以使用以下方法将程序集安装到GAC中:

To install the assembly into GAC on production or user’s machine, you may install the assembly into GAC using:

  • Windows Installer, by creating .msi package;
  • Any other installer system that supports installing to GAC, e.g. Inno Setup;
  • System.EnterpriseServices.Internal.Publish.GacInstall method. PowerShell example:

Add-Type -AssemblyName "System.EnterpriseServices"
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("WinSCPnet.dll")

必须指定DLL的绝对路径,否则上述方法将失败(并且唯一的失败指示将发送到Windows事件日志).

Absolute path to the DLL is required to be specified or the above method will fail (and the only indication of the failure is sent to Windows Event log).

  1. 请参见如何在SSIS脚本任务中修复NuGet WinSCP.NET?
  1. See How to fix NuGet WinSCP.NET in SSIS Script Task?

这篇关于从SQL Server代理运行时,引用WinSCPnet.dll的SSIS C#2012脚本任务失败,并且“调用的目标已引发异常".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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