开发者

Windows 7 .net Excel .SaveAs() Error Exception from HRESULT: 0x800A03EC

开发者 https://www.devze.com 2022-12-15 16:05 出处:网络
Background: I toasted my old hard drive at work and am getting a new one. With that I\'ll have to rebuild my machine. My manager has Windows 7 installed on him loaner laptop that I\'ve been using whil

Background:

I toasted my old hard drive at work and am getting a new one. With that I'll have to rebuild my machine. My manager has Windows 7 installed on him loaner laptop that I've been using while my machine is out of commision. But I've run into a problem.

We have a fair number of apps that make use of the Microsoft.Office.Interop.Excel reference. I've gotten past a few errors so far but the one I've been stuck on for the last few days (my machine actually suffered the hard drive failure after the first rebuild) and have been unnable to find a fix. I have searched for this error but can't find anyone having this problem on Windows 7, although I have tried other fixes for Windows Server 2008 to no avail.

If I can't fix this problem, I will not be able to use Windows 7 and would like to know that before I rebuild a machine only to have to wipe it and start again (for the third time).

Problem:

OS: Windows 7 Enterprise

Error Message: Exception from HRESULT: 0x800A03EC

Code:

Private m_xls As Microsoft.Office.Interop.Excel.Application
Private m_wkbk As Microsoft.Office.Interop.Excel.Workbook
Private m_wksht As Microsoft.Office.Interop.Excel.Worksheet
m_xls = New Application
m_xls.Visible = False : m_xls.DisplayAlerts = False
m_wkbk = m_xls.Workbooks.Open(Me.FilePath)
m_wksht = CType(m_wkbk.ActiveSheet, Worksheet)
'.开发者_StackOverflow中文版..Write some data...'
m_wkbk.SaveAs(Me.FilePath, XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, False, False, XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)

The error occurs on the final line.

What I've tried so far:

  1. Changing the AppPool to use the NetworkService account (it was 'ApplicationPoolIdentity' which I couldn't find in the user list in security settings). Then giving the NetworkService account full access to the appropriate folder.
  2. Giving NetworkService access to all 'Microsoft Excel Application' settings in DCOMCNFG
  3. Running this command "appcmd set config -section:asp -enableParentPaths:true" because it's the only other thing I could find
  4. Using the .SaveCopyAs() which worked but caused different errors

I just wanted to see if anyone else has run into this or not since Windows 7 is new. I can go with Server 2008 but I would like to have some solid reasoning behind it before I tell my manager it won't work.

Thank you, Jeff


Note: This needs to be condensed a bit as it's a compilation of all the fixes I've been making on our internal wiki but I'm not sure what subset of changes made it work so I'll include it all.

Solution:

The following changes may be a superset of how to address this problem.

-Run DCOMCNFG.exe and navigate to 'Component Services>Computers>My Computer'.
-Right click 'My Computer' and click 'Properties'.
-Open the 'COM Security' tab. Add your account for everyone of the buttons listed ('Edit Limits...' and 'Edit Default...' buttons under 'Access Permission' & 'Launch and Activate Permissions'). Give your account all access options. Click 'Apply' then 'OK'.
-While still in DCOMCNFG expand the 'My Computer' link and open the 'DCOM Config' folder.
-Right click on 'Microsoft Excel Application' and select 'Properties'.
-Under the 'Security' tab choose the 'Customize' option for 'Launch and Activation Permissions' and 'Configuration Permissions'. For both click the 'Edit...' button. Give your account access to everything.
-While still in the 'Properties' for 'Microsoft Excel Application' go to the 'Identity' tab.
-Select the 'The Interactive User' option.
-Click 'Apply' then 'OK'.
-Restart your computer.

-Try the below DCOMCNFG & ApplicationPoolIdentity change.

-Run command prompt as Administrator.
-Navigate to c:\Windows\System32\inetsrv> and run 'appcmd set config -section:asp -enableParentPaths:true'

Alternately you could use .SaveCopyAs() although this may still not address the problem and will require code changes.

DCOMCNFG For windows 7:

This error happens on 'Excel app = New Application();' calls

This link details how to fix the problem for XP/Server 2003 but can be adapted to Windows 7: http://blog.crowe.co.nz/archive/2006/03/02/589.aspx

I do not have/could not find an 'ASPNET' account. You have to check the application pool to find out what the app is running as.
To do that go into 'Computer Management>Services and Applications>Internet Information Services>Application Pools'
Right click on the appropriate AppPool and choose 'Advanced Settings'. Under 'Process Model>Identity' you can find the account it is running under. Mine was 'ApplicationPoolIdentity' which I also couldn't find so I changed it to 'Network Service' like Windows Server 2003.
Once this is set run DCOMCNFG.exe. Navigate to 'Component Services>Computers>My Computer>DCOM Config'.
Find and right-click on 'Microsoft Excel Application' and select 'Properties'. Choose the 'Security' tab. Under 'Launch and Activation Permissions' choose 'Customize' and click 'Edit'.
Then click the 'Add...' button.
Type the name of the the appropriate account, in this case 'Network Service' and click 'Check Names'. Then click 'OK'.
Back on the 'Launch and Activation Permissions' page highlight the 'Network Service' account and check the 'Local Launch' and 'Local Activation' check boxes. Then click 'OK'.


When I was getting this error, I think I started using .SaveCopyAs instead of SaveAs. I'm not sure what other errors this is causing you, if you could elaborate there perhaps something could be figured out for that situation.

Also, one thing that you are doing is most likely causing excel.exe to remain in memory after processing a file. Here is an article that shows the proper way to use and release COM interop objects (http://support.microsoft.com/kb/317109). It is a pain, but it worked for me in allowing those resources to be released before the app closed.


Make sure you're running the program (and EXCEL.EXE) as administrator, and the directory you're saving to doesn't have "read-only" attribute on.

Also, try passing the full file path instead of just the file name.

You could also try passing System.Reflection.Missing.Value instead of omitting the optional parameters.

Can't think of anything else right now. Hope this helps.

ShdNx


The answer above by Jeff Keslinke ended up working for me. You also need to look at the application pool that your App is using and make sure the identity is correct and has full access and privileges.


I got the same issue and found application crash errors with Exception code: 0xc0000005 in windows events. Search web and find the following solution at the linkExcel 2010 Crash, Exception code: 0xc0000005 Rename the file extension of the opened file from xlsx to zip. The solution works for my case.


Try turning on ISS . The details are mentioned here for windows 7

http://helpdeskgeek.com/windows-7/turn-on-microsoft-internet-information-services-in-windows-7/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号