SSIS Agent job fails when disconnecting from RDP Remote session with (X)

0

I have an SSIS package that takes an Excel document and refreshes the Queries and pivots within the document, then saves it and then sends it to a destination via "Send email task".

So first of all the first issue was that the SSIS package runs perfectly (with no errors) when I run it from SSMS 2018 (SQL Server 2019 Dev) and VS 2019, but when using SQL Server Agent, then it didn't seem to execute the script task. I then figured out that I should use windows key + run with dcomcnfg, then go the DCOM Config, then go to properties of Microsoft Excel Application and change the identity form "The launching user" to "this user".

If I use my account CAPCUBED_VM\Ruahl Behr or the Admin account then it runs perfectly but then the problem is that I can't open excel normally as it gives me the error:

Cannot use object linking and embedding".

So then I tried using "The interactive user" and this runs perfectly with SQL Agent Job. The problem I am facing now is when I am connected the the RDP the package runs perfectly through SQL Server Agent (Schedule), but when I disconnect form the RDP (using the "X") the package gives me the following error then:

Update Daily WIP Group View:Error: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password. (Exception from HRESULT: 0x8000401A).

I have SQL Server Agent set to use Local System account.

Could this maybe be something to do with the actual folder where the Excel documents are saved?

UPDATE:

I found that when I only run the "Send email task" then the package works fine even when disconnected from RDP, but found that the script task is where the problem lies. Could there be something wrong in my code?

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


namespace ST_0163e0491a714593a4e34d0175f0e112
{

    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPoint]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion


        public void Main()
        {
            ExcelRefresh(@"C:\Users\Ruahl Behr\Desktop\Daily WIP\Daily WIP Report - Group.xlsm");
            Dts.TaskResult = (int)ScriptResults.Success;
        }

        private void ExcelRefresh(string Filename)
        {
            object NullValue = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application
            {
                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();

            excelApp.Application.CalculateUntilAsyncQueriesDone();

            //System.Threading.Thread.Sleep(120000);

            //Run Macro Fix Dates
            excelApp.Run("Fix_Dates");

            //Refresh Pivot Tables
            foreach (Microsoft.Office.Interop.Excel.PivotCache pt in Workbook.PivotCaches())
                pt.Refresh();

            Workbook.Save();
            Workbook.Close(true);
            excelApp.Quit();
            Workbook = null;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
        }
    }
}
c#
sql-server
excel
ssis
sql-server-agent
asked on Stack Overflow Mar 18, 2020 by Ruahl Behr • edited Mar 23, 2020 by Ruahl Behr

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0