SSIS package Error which contains an excel script task through SQL Server Agent job

白昼怎懂夜的黑 提交于 2021-01-08 02:09:52

问题


I have an SQL Server 2012 SSIS package with a script task to refresh an excel file. When I run manually in Visual Studio it executes fine, no problems.

When I execute the package through an SQL Agent job, it fails with the following message:

Package execution on IS Server failed. Execution ID: 357243, Execution Status:4.

The message in the Integration Services Catalogs:

Script Task Error: Exception has been thrown by the target of an invocation.

All other packages that don't have a script task can be successfully executed via SQL Agent job.

I've tried the solution on link:
https://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-x64?forum=innovateonoffice

by setting up folders:

C:\Windows\SysWOW64\config\systemprofile\Desktop  
C:\Windows\System32\config\systemprofile\Desktop

I've also followed the suggestions on
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/4a20219e-4a90-41be-acfe-b8846dc2c38a/error-while-executing-a-ssis-package-which-contains-a-script-task-through-sql-server-agent-job?forum=sqlintegrationservices with no luck.

I'm hoping someone will have another suggestion.

My script task is:

#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;

    /// </summary>
    public void Main()
    {
        string TemplatePath = Dts.Variables[@"User::TemplatePath"].Value.ToString();

        Excel.Application MyApp = new Excel.Application();
        Excel._Workbook Template = null;

        MyApp.Visible = false;
        Template = MyApp.Workbooks.Open(TemplatePath);
        Template.RefreshAll();
        Template.Close(true);
        Dts.TaskResult = (int)ScriptResults.Success;
    }

来源:https://stackoverflow.com/questions/43109391/ssis-package-error-which-contains-an-excel-script-task-through-sql-server-agent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!