0

I'll start saying I'm relatively new to SSIS development. I have a process that executes a Select and stores the data into an excel (This works like a charm). On the next step, the excel is now converted into a pdf file. But on that execution, the code returns the error 0x800A03EC. This is the line:

excelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, pdfpath);

Its worth saying that this has been working for years, and only now started failing. Its also worth to say that I encountered some more problems with other Interop functions as the Range.CopyPicture().

This is the whole code.

public void Main()
        {
            Dts.TaskResult = (int)ScriptResults.Success;

            //Totally fine paths
            string excelpath = ""
            string pdfpath = ""

            //No idea why is this here 
            System.Threading.Thread.Sleep(2000);

            Microsoft.Office.Interop.Excel.Application excelApplication;
            Microsoft.Office.Interop.Excel.Workbook excelWorkbook;
            excelApplication = new Microsoft.Office.Interop.Excel.Application();
            excelApplication.ScreenUpdating = false;
            excelApplication.DisplayAlerts = false;
            excelWorkbook = excelApplication.Workbooks.Open(excelpath);

            if (excelWorkbook == null)
            {
                excelApplication.Quit();

                excelApplication = null;
                excelWorkbook = null;
                
            }
            
            try
            {
                excelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, pdfpath);
            }
            catch (System.Exception ex)
            {
                Dts.TaskResult = (int)ScriptResults.Failure;
            }
            finally
            {
                // Close the workbook, quit the Excel, and clean up regardless of the results...
                excelWorkbook.Close();
                excelApplication.Quit();

                excelApplication = null;
                excelWorkbook = null;
            }
 
}

The paths are totally fine, I also checked no excel process was running on the background before the process started. I also tried executing with different users... Nothing seems to work.

Could anyone give a helping hand?

Thank you very much.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • From my experience with `0x800A03EC`: it's not your code that has the problem, rather, it's much more likely something went wrong in the Windows Registry (possibly/probably from an Office installation/update). It's not easy for us to help you though – Camilo Terevinto Aug 02 '21 at 08:39

1 Answers1

0

The error code 0x800A03EC (or -2146827284) means NAME_NOT_FOUND. In other words, you've asked for something, and Excel can't find it. This is also a good indicator that Excel is automated from a service or run on the server. Here is what MS states for that:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Read more about that in the Considerations for server-side Automation of Office article.

If you deal with Open XML documents only consider using components that allow generating PDF without Office applications, see Save Open XML as PDF for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45