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.
1. Login to the server as a administrator.
2. Go to "Start" -> "Run" and enter "taskmgr"
3. Go to the process tab in task manager and check "Show Processes from all
users"
4. If there are any "Excel.exe" entries on the list, right click on the
entry and select "End Process"
5. Close task manager.
6. Go to "Start" -> "Run" and enter "services.msc"
7. Stop the service automating Excel if it is running.
8. Go to "Start" -> "Run" and enter "dcomcnfg"
9. This will bring up the component services window, expand out "Console
Root" -> "Computers" -> "DCOM Config"
10. Find "Microsoft Excel Application" in the list of components.
11. Right click on the entry and select "Properties"
12. Go to the "Identity" tab on the properties dialog.
13. Select "The interactive user."
14. Click the "OK" button.
15. Switch to the services console
16. Start the service automating Excel
17. Test you application again.
u really saved my second day cause it was running fine while i debug it but after hosting in iis was giving trouble thanks a lot have g8 day
enjoy coding
With above solution , i can import/exprot files if i save that file and directly import.but if i say open in broadcasted file
(code for reference :
window( Response.AddHeader("content-disposition", "attachment;filename=Export.xls");
Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";)
in excel 2007 then it is saying that not proper formate and if i say yes to open it will open correclty but when i import it it is throwing com error.
this works perfact in excel 2003.
What changes do i need to do to make it working in Excel 2007 ?
Yes, Interacting user solve my problem alone with adding more security users(permissions) and downloading CutePDF to make (xlWorkBook.ExportAsFixedFormat()) as PDF work:
I know this post is a little old, but this might help someone:
Select Case (extension)
Case ".pdf"
contentType = "application/pdf"
Case ".xls"
contentType = "application/vnd.ms-excel"
Case ".xlsx"
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet "
Case ".doc"
contentType = "application/msword"
Case ".docx"
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
Case ".txt"
contentType = "text/plain"
Case ".csv"
contentType = "application/octet-stream"
Case ".png"
contentType = "image/png"
Case ".jpg"
contentType = "image/jpeg"
Case ".jpeg"
contentType = "image/jpeg"
Case ".gif"
contentType = "image/gif"
Case Else
Throw New NotSupportedException("Unrecognized file type.")
'contentType = "application/octet-stream"
End Select
I'd have to debug the code to determine what the issue is. I have had no problems with Office 2007 products.
Selecting "The interactive user" solved my proble.
I have invested 1 and half day almost to resolve the issue and i was disappointed with all the solution found by googling..this is the one wich solve my proble.Thanks very much.I want to understand why this setting is neccessary..if anybody can reply.
Thanks a lot. Your solutions worked like a charm.
Actualy my problem was on this line code:
execute @rs = master.dbo.sp_OAMethod @xlWorkBooks, 'Open', @xlWorkBook OUTPUT, 'D:\itWorks.xls'
But @rs returned the same error
thanks a lot
I'm going to test this solution over the next few days and see if this also solves my problem. Thank you very much for the very detailed comment.
I ran into exactly the same problem. Running from a console window worked fine, running from a SQL job failed at the "SaveAs". I also beat my head against the wall for awhile. Then I noticed "SaveCopyAs" and figured...what'd I have to lose?
SUCCESS!!
Of course, this will be "fixed" in a "future releas/service pack"! :-(
Don
My code has problem on "Open" and there's no "OpenCopy" or anything :(
That actually sounds like a different problem - as if the file is already locked by the OS. Make sure that the file isn't being held open by a previously crashed process or improperly closed stream.
i had the same problem but it works using SaveCopyAs and thanks for this article