You are hereException from HRESULT: 0x800A03EC - Excel, .Net, SQL and Windows Server 2008
Exception from HRESULT: 0x800A03EC - Excel, .Net, SQL and Windows Server 2008
For the last 5 days, I have been encountering an error when trying to automate the creation of an Excel document through a scheduled SQL Server job. The error I was receiving was -
Exception from HRESULT: 0x800A03EC
Let's take a step back. The same code I had written worked on my development machine, worked on other target servers while scheduled as SQL jobs, but the code would not work on the following target server -
- Windows Server 2008 Standard
- 64-bit platform
- SQL Server 2005
- Excel/Office 2007 Professional
After adding some StackTrace code to my program, I was able to determine that the EXE was failing on the Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs line. After trying multiple iterations of the SaveAs command (a quick Google search provided some potential solutions), I continued to get the same 0x800A03EC error code. I went down the road of thinking it was a problem with my 32-bit development environment and had our Sysadmin build me a 64-bit virtual machine for me to compile my application; however, this also yielded the same error. I made sure that the Excel assemblies on the development environment and the target machine were the same version. On the target server, I went to dcomcnfg, selected the Microsoft Excel Application entry and made sure it was using the "interactive user" and still no luck. I made sure that, for testing only, all the SQL services ran under my domain admin account to account for SQL security differences and still nothing.
At this point I decided that I was spinning my wheels and I would call Microsoft and use one of my MSDN support cases.
After speaking to several departments, I finally reached the Office department who tried to help. After explaining my issue quite a few times over and over, I finally got the response I had dreaded - it can't be done that way. Ugh. I had feared I would get this response after reading that using Open XML to create Office documents was the recommended approach and that using the Office COM references was no longer supported (if it ever was) and Windows 2008 has additional security that prevents the old approach from working properly. Well, I guess that explains why it wasn't working.
So where do I go from here? Even though Microsoft support couldn't provide me with sample code or a link to some code, I was able to find this knowledge base article detailing how to to create Excel files using Open XML. Hopefully, this approach will work on my target server environment.