简体   繁体   English

调用的目标已引发异常 - SSIS 脚本任务错误

[英]Exception has been thrown by the target of an invocation - SSIS Script Task Error

I have the following script task using C# to refresh the pivot table in Excel in an SSIS package. I have the following script task using C# to refresh the pivot table in Excel in an SSIS package. The package runs well in the Visual Studio as well as the package utility. package 在 Visual Studio 以及 package 实用程序中运行良好。 But when I deployed this package to SSIS Catalog and schedule a SQL Server Agent job, it failed on the script task part with a very generic error message但是,当我将此 package 部署到 SSIS 目录并安排 SQL 服务器代理作业时,它在脚本任务部分失败,并带有非常通用的错误消息

Exception has been thrown by the target of an invocation调用的目标已抛出异常

I have researched a couple of other Q&As but our situations differ a lot.我研究了其他几个问答,但我们的情况有很大不同。

My script task code我的脚本任务代码

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
#endregion

namespace ST_0126969a11e546b3bbde047669039ab5
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        public void Main()
        {
            //Dts.TaskResult = (int)ScriptResults.Success;

            ExcelRefresh(@"C:\\SSIS\\MTD.xlsx");
        }

        private void ExcelRefresh(string Filename)
        {
            object NullValue = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            excelApp.DisplayAlerts = false;
            Microsoft.Office.Interop.Excel.Workbook Workbook = excelApp.Workbooks.Open(
               Filename, NullValue, NullValue, NullValue, NullValue,
               NullValue, NullValue, NullValue, NullValue, NullValue,
               NullValue, NullValue, NullValue, NullValue, NullValue);
            Workbook.RefreshAll();

            Workbook.Save();
            //Workbook.SaveAs(DestinationPath, NullValue, NullValue, NullValue, NullValue, 
            // NullValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, 
            //NullValue, NullValue, NullValue, NullValue, NullValue);
            Workbook.Close(false, Filename, null);
            excelApp.Quit();
            Workbook = null;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
        }
    }
}

Please help.请帮忙。

Option A - Microsoft Office has not been installed on the server.选项 A - 服务器上尚未安装 Microsoft Office。 The technical answer being "install and license Office" but that's generally not a good thing as I mention over here https://stackoverflow.com/a/37870251/181965技术答案是“安装和许可 Office”,但这通常不是一件好事,正如我在这里提到的https://stackoverflow.com/a/37870251/181965

Option B - Office is installed but you are executing the SSIS package in a different bit-edness than the installed version.选项 B - Office 已安装,但您正在以与已安装版本不同的位元执行 SSIS 包。 If you installed the 32 bit version of Office, which is the default, then you need to run the SSIS package in a similar domain.如果您安装了 32 位版本的 Office,这是默认的,那么您需要在类似的域中运行 SSIS 包。 The default execution version of SSIS on a SQL Server box will be the 64 bit so either use the 32 runtime or redo the Office installation to match the default invocation. SQL Server 机器上 SSIS 的默认执行版本将是 64 位,因此要么使用 32 位运行时,要么重做 Office 安装以匹配默认调用。 Also addressed in the aforementioned answer也在上述答案中提到

Option C - Permissions.选项 C - 权限。 Does the account that is running the SSIS package have access to the file system at C:\\SSIS\\ Does the account have write permission for that location?运行 SSIS 包的帐户是否有权访问位于 C:\\SSIS\\ 的文件系统 该帐户是否对该位置具有写入权限?

Option D - Does the location and the file exist?选项 D - 位置和文件是否存在?

Option E - Does the account that is executing the package have the InteractWithDesktop bit checked within active directory - assuming it's a service account选项 E - 执行包的帐户是否在活动目录中检查了 InteractWithDesktop 位 - 假设它是一个服务帐户

Option F - Are you running the same version of SSIS on the Server as you developed against?选项 F - 您在服务器上运行的 SSIS 版本与您开发的版本相同吗?

Option G - Everything is actually running fine but since you've commented out the return code in Main, the task is failing.选项 G - 一切实际上运行良好,但由于您已在 Main 中注释掉返回代码,因此任务失败。

Those are my top thoughts of where this has gone haywire.这些是我对这一切失控的最重要的想法。

"Exception has been thrown by the target of an invocation" is a general exception thrown by Script task once an error occurs. “异常已被调用的目标抛出”是脚本任务在发生错误时抛出的一般异常。 To read the real error message, you can add a try, catch block to your code as explained in the following article:要阅读真正的错误消息,您可以在代码中添加 try、catch 块,如下文所述:

While looking at your code, It looks like the error is thrown due to one of the following reasons:在查看您的代码时,似乎由于以下原因之一引发了错误:

  • Microsoft Office Interop assemblies are missing on the server (office is not installed)服务器上缺少 Microsoft Office 互操作程序集(未安装 office)
  • The Excel file path is incorrect Excel文件路径不正确

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SSIS 脚本任务 Excel 连接打开:调用目标抛出异常 - SSIS Script Task Excel connection open: Exception has been thrown by the target of an invocation SSIS:调用目标已抛出错误异常 - SSIS: Error Exception has been thrown by the target of an invocation 脚本任务中的“调用目标抛出了运行时错误异常” - “Runtime error Exception has been thrown by the target of an invocation” from Script task SSIS 脚本任务获取“调用目标已抛出异常”。 使用第 3 方 dll 运行时 - SSIS Script Task getting "Exception has been thrown by the target of an invocation." when running with 3rd party dll 调用的目标已引发异常(SSIS & WinSCP & C#) - Exception has been thrown by the target of an invocation (SSIS & WinSCP & C#) 配置错误-调用目标已引发异常 - Configuration Error - Exception has been thrown by the target of an invocation 错误“VS2013中的调用目标已抛出异常” - Error “Exception has been thrown by the target of an invocation” in VS2013 是什么导致此错误“调用目标已引发异常”? - What Generates This Error 'Exception has been thrown by the target of an invocation'? 奇怪的错误:调用的目标引发了异常 - Strange error: Exception has been thrown by the target of an invocation Hazelcast DotNet客户端错误:调用的目标引发了异常 - Hazelcast DotNet client Error: Exception has been thrown by the target of an invocation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM