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;
}