(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

0

We have one SSIS Package which has one Script task- And the script task is using C# 2012 version. The job is to open an excel file and modify the column width and save it. Everything working fine on my local machine. when I deployed this package on to the Production server. The package failed. i'm getting this error-

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Here is the Script task code :

public void Main()
    {
        try
        {
        // TODO: Add your code here
        Excel.Application xlp = new Excel.Application();
        Excel.Workbooks wrkbs = xlp.Workbooks;
        Excel.Workbook wrkb = wrkbs.Open(Dts.Variables[@"User::Source"].Value.ToString());
        Excel.Sheets sht = wrkb.Worksheets;

            try
            {

            //sheet1 formating
            Excel.Worksheet wst = (Excel.Worksheet)sht.get_Item(1);
            wst.Columns.AutoFit();
            wst.Rows.AutoFit();
            Excel.Range rngQ = wst.get_Range("Q:Q", Type.Missing);
            rngQ.ColumnWidth = 18.43;
            Excel.Range rngR = wst.get_Range("R:R", Type.Missing);
            rngR.ColumnWidth = 14.86;
            Excel.Range rng1 = wst.get_Range("1:1", Type.Missing);
            rng1.RowHeight = 15.75;
            //sheet2 formating
            Excel.Worksheet wst2 = (Excel.Worksheet)sht.get_Item(2);
            wst2.Columns.AutoFit();
            //sheet3 formating
            Excel.Worksheet wst3 = (Excel.Worksheet)sht.get_Item(3);
            wst3.Columns.AutoFit();
            wrkb.Save();
            wrkb.Close();
            xlp.Quit();
            System.Threading.Thread.Sleep(60000);
              }
              finally
              {
                 if (sht != null) Marshal.ReleaseComObject(sht);
                 if (wrkb != null) Marshal.ReleaseComObject(wrkb);
                  if (wrkbs != null) Marshal.ReleaseComObject(wrkbs);
                if (xlp != null) Marshal.ReleaseComObject(xlp);
             } 
        }
        catch (Exception em)
        {
            string er = Dts.Variables[@"User::ERROR"].Value.ToString();
            using (StreamWriter sw = File.CreateText(er + "Error_Format_StatusChangeR_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".log"))
            {
                sw.WriteLine(em.Message.ToString());
            }

        }


        Dts.TaskResult = (int)ScriptResults.Success;
    }

PLease help me with this

c#
sql-server
excel
ssis
com
asked on Stack Overflow Apr 10, 2019 by Bumblebee • edited Apr 10, 2019 by jarlh

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0