Claus on Code

A data dudes random musings about code, bugs, products, life etc.


MS, seriously!!! SSIS and System.Runtime.InteropServices.COMException (0x800A03EC)

Let me describe my problem. Maybe you have the same, if you have googled for the error code, and found this page.

So, I’m downloading an old Excel file from a German webpage. The Excel file is in a spreadsheetML format, which is impossible to read from SSIS.

No worries, I can easily with a script task, convert the file to CSV, using C# and the Excel API. Like so

….
using MS.Internal.Xml;
using Microsoft.Office.Interop.Excel;
…….

Microsoft.Office.Interop.Excel.Workbook wb1 ;
Microsoft.Office.Interop.Excel.Application wb2 =
new Microsoft.Office.Interop.Excel.Application();
wb2.DisplayAlerts = false;
wb1 = (Microsoft.Office.Interop.Excel.Workbook)wb2.Workbooks._Open(filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

if (wb1.FileFormat == Microsoft.Office.Interop.Excel.XlFileFormat.xlXMLSpreadsheet)
{
wb1.SaveAs(filename.Replace(“.xls”,”.csv”) , Microsoft.Office.Interop.Excel.XlFileFormat.xlCSVMSDOS , Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,false,false,false,false,false);
}
else
{
wb2.Workbooks.Close();
}
wb2.Workbooks.Close();

Now I can read the data with a SSIS CSV data source. This Works fine, when I run my SSIS package from BIDS. When I put it in to production, and run the package with the SQL server agent, I get the following error:

Service cannot be started. System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file ‘c:\XXXX’. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.

None of the above is my problem. I think I tried everything to find a solution to the problem. It turns out, that it is a bug in windows server 2008. There are some different solutions on the web, which include changing the registry values on the server.

Since I’m a consultant, and hence an expensive resource, I would like not to fuck anything up, playing around with registry values.

I found an easier fix however. Apparently, the folder C:\Windows\SysWOW64\config\systemprofile\Desktop has been removed from Windows server 2008. It was present in windows server 2003.

When I created the folder, everything worked fine. Apparently the desktop folder is necessary, if you want to manipulate Excel files with code from the SQL server agent. Scary.

So, the answer: if you have problems manipulating office files from code executed from the SQL server agent on windows server 2008 create the folder C:\Windows\SysWOW64\config\systemprofile\Desktop (C:\Windows\System32\config\systemprofile\Desktop if it is 32bit)

That was it for now. Bye bye:-)



23 responses to “MS, seriously!!! SSIS and System.Runtime.InteropServices.COMException (0x800A03EC)”

  1. Owosome man! you saved my life today. Didn’t expected windows will have this kind of bug… 🙂

  2. Nithesh Erakkara Avatar
    Nithesh Erakkara

    Hi Claus,

    I’m trying to read excel file from SharePoint 2010. I was also facing the problem mentioned above. I have created the folder and gave full control rights to IIS AppPool\DefaultAppPool on the folder. Still I’m getting COM Exception.

    Can you guide me what more I can do?

  3. Hi Nithesh,

    No, sorry, it is to long ago 🙁 If the above don’t work, then I don’t know how to fix it 🙁

  4. Thanks man your solution worked absolutely fine.

    I am not sure why Excel object need “Desktop” folder over there.

    How could we manage to create on User’s machines. ?

  5. Christopher Haws Avatar
    Christopher Haws

    You rule. I have been trying to figure this out for the last 12 hours and came across your blog post. Worked like a charm!!

  6. Great 🙂

  7. Seriously, if I could kiss you, I would. Thank you so much! I had tried everything 🙂

  8. Hehe 🙂

  9. Unbelievable! Just when you think you have seen everything… I think someone should write a book on work arounds and fixes for this stuff

    Thank You!

  10. Np 🙂

  11. Thank you very much! You saved my day!
    I was facing this problems since a few weeks and couldn’t find a solution so far, your’s helped!

  12. Glad to hear it 🙂

  13. Wow. Been working on this issue off and on for a number of days, and now that I finally got it to spit out an HRESULT, your post is the solution. Thanks much!

  14. This saved me as well, thanks a lot!

  15. Awesome .. I was pulling my hair out on this too .. I test my code via win32 app and it works there. But it failed when I build my window service. Creating the Desktop folder save the day. Thanks much

  16. I’ve been debugging what I thought were permission issues related to our service account the entire day with no success. Finally stumbled upon your post. Your solution worked. I can’t believe it worked, but it did!! Thank you! Are you kidding me MSFT?!

  17. absolutely fantastic! thank you!

  18. I have no luck, The desktop folder has created both the server where i run the package, and the machine where i stored the excel file. any other posiblity solutions?

  19. Finally i get this work if DESKTOP folder did not help,

    Start
    Run
    mmc -32
    File
    Add Remove Snap-in
    Component Services
    Add
    OK
    Console Root
    Component Services
    Computers
    My Computer
    DCOM Config
    Microsoft Excel Application -> Right click -> Properties
    On Security tab, give full permissions to the domain user and NT SERVICE\SQLSERVERAGENT on: a. Launch and Active Permissions b. Access Permissions c. Configuration Permissions
    On Identiy tab -> change to Interactive User

    from this post:https://stackoverflow.com/questions/35642527/unhandled-exception-system-runtime-interopservices-comexception-0x800a03ec

    Cheers!!

  20. Thank you ! Sad to see this ‘bug’ still exists in Windows 10 🙂 Saved our day

  21. I don’t usually comment on anything on a website.
    This literally saved my day so thanks for that!

  22. For me it worked, I don’t have the error any more, but now the job never stops running, but when I execute the package from the catalog works fine 🙁
    I think that maybe some window o prompt opens and the job is stuck there.
    This is my code:
    Dim excel As New Microsoft.Office.Interop.Excel.Application
    Dim wb As Microsoft.Office.Interop.Excel.Workbook
    wb = excel.Workbooks.Open(“C:\\Users\\Oliver\\Desktop\\refreshtest_pq.xlsx”)
    wb.RefreshAll()
    wb.Save()
    wb.Close()
    excel.Quit()
    Runtime.InteropServices.Marshal.ReleaseComObject(excel)

Leave a Reply

Your email address will not be published. Required fields are marked *