"Retrieving the COM class factory for component.... error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

31

I just created a simple application and hosted in IIS6.0. In code I'm just instantiating excel objects.

using excel = Microsoft.Office.Interop.Excel.Application;

namespace TestHosting
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            excel excelObj=new Microsoft.Office.Interop.Excel.Application();
        }
    }
}

Its giving me following error

 "Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

System Configuration:

Windows server 2008,enterprise edition with 64 bit. service pack 2

I tried with many possible solutions found on internet,but none of them were worked for me.

Some solution I tried are below

1) creating Desktop application under the path "C:\Windows\SysWOW64\config\systemprofile" 2)setting full permission/control for Microsfot.EXcelApplicaiton in DCOMCNFG 3)Killing all excel instances in Task Manager

Please help me in this regard,this is just sample app but in my original app is mostly about read and writing data from/to excel.

asp.net
excel
iis
asked on Stack Overflow Jul 22, 2013 by Ram • edited Oct 22, 2015 by bot

14 Answers

50
  1. Make sure that you have Office runtime installed on the server.
  2. If you are using Windows Server 2008 then using office interops is a lenghty configuration and here are the steps.

Better is to move to Open XML or you can configure as below

  • Install MS Office Pro Latest (I used 2010 Pro)
  • Create User ExcelUser. Assign WordUser with Admin Group
  • Go to Computer -> Manage
  • Add User with below options
  • User Options Password Never Expires
  • Password Cannot Be Change

Com+ Configuration

  • Go to Control Panel - > Administrator -> Component Services -> DCOM Config
  • Open Microsoft Word 97 - 2003 Properties
  • General -> Authentication Level : None
  • Security -> Customize all 3 permissions to allow everyone
  • Identity -> This User -> Use ExcelUser /password
  • Launch the Excel App to make sure everything is fine

3.Change the security settings of Microsoft Excel Application in DCOM Config.

Controlpanel --> Administrative tools-->Component Services -->computers --> myComputer -->DCOM Config --> Microsoft Excel Application.

Right click to get properties dialog. Go to Security tab and customize permissions

See the posts here: Error while creating Excel object , Excel manipulations in WCF using COM

answered on Stack Overflow Aug 2, 2013 by bot
37

Sometimes, you create new application pool and cann't solve it via DCOMCNFG. Then there is another method to do:

Set the Identity (Model Name) of application pool to LocalSystem.

I don't know the root cause, but it solve my problem one time.

answered on Stack Overflow Mar 13, 2014 by Luis Sérgio
7

Too late to respond. But, if this helps someone who is still facing the issue. I got this fixed by:

→ Set site on dedicated pool instead of shared one.

→ Enable 32 bit application support.

→ Set identity of the application pool to LocalSystem.

answered on Stack Overflow May 16, 2016 by Hardik V.
4
  1. give the read / write permission to the IIS user or group users

  2. Start -> run -> inetmgr

    enable the ASP.NET authentication for your default website

3. For 64-bit (x64), create this folder: C:\Windows\SysWOW64\config\systemprofile\Desktop

For 32-bit (x86), create this folder: C:\Windows\System32\config\systemprofile\Desktop

The windows service, if running under the systemprofile, needs the Desktop folder. This folder was automatically created on XP and older Windows Server versions, but not for Vista and Windows 2008 Server.

answered on Stack Overflow Jul 22, 2013 by dotnetandsqldevelop
3

solution that worked for me is to change user under which Application Pool is started (ApplicationPoolIdentity obviously has not enough rights to access COM object).

Good luck!

answered on Stack Overflow Sep 20, 2013 by Milos
3

try to do the following:

  1. Make sure Office interop assemblies are installed.
  2. Check the version of the assemblies on development and production.
  3. Create Desktop folder under systemprofile.
  4. set the DCOM security explicitly for the service user.

you can find more details here

answered on Stack Overflow Jan 27, 2014 by user3140982 • edited Feb 27, 2014 by user3140982
3

Personally, I ran these exact steps:

* Install Interop Assemblies: you can install from Microsoft's website https://www.microsoft.com/en-us/download/details.aspx?id=3508&tduid=(09cd06700e5e2553aa540650ec905f71)(256380)(2459594)(TnL5HPStwNw-yuTjfb1FeDiXvvZxhh.R.Q)()

* Check assemblies version: check the version of the assemblies on development and production machines. The assemblies will be in the GAC, in widows 7 this folder is %windir%\assembly.

* Create a Desktop folder: the service uses the desktop folder under systemprofile so you will need to create this folder if not there, here is the location of the folder: For 64 bit applications : C:\Windows\SysWOW64\config\systemprofile\Desktop For 32 bit applications : C:\Windows\System32\config\systemprofile\Desktop

* Add DCOM user permissions:
---start the run window and type 'dcomcnfg'.
---Expand Component Services –> Computers –> My Computer –> DCOM Config.
---Look for Microsoft Excel Application. Right click on it and select properties, then select the Security tab.
---Select the Customize radio button under 'Launch and Activation Permissions' and 'Access Permission' and click the Edit button for both to add users as follows.
---------Click the Add button and users 'IIS_IUSRS' and 'NETWORK SERVICE' and give them full privileges.
---Go to the Identity tab and select "The interactive user" option.
---Click Apply and OK.

answered on Stack Overflow Feb 26, 2016 by IsaacBok
2

I just created a simple application

What is the target processor of the application? I am guessing it is x86 - so either set it to x64 or anycpu.

I think the issue you are having is due to a 64bit process trying to access a 32bit dll.

Also, if you can't change the target processor you could try to enable 32-bit Applications from the Application Pools settings in IIS.

answered on Stack Overflow Aug 6, 2013 by Fraser
2

Do you have Excel installed on the server? The interop interfaces you're using are used to automate Excel which requires that the Excel application is installed there. Each page request cycle will potentially launch a separate instance of excel.exe. I would strongly advise against doing this as part of a web application.

Why do you want to do this? If you are wanting to generate Excel documents, there are much better ways to do this, including OpenXML as mentioned elsewhere on this thread. Please do not run Excel on the server!

Link to OpenXML SDK download: http://www.microsoft.com/en-us/download/details.aspx?id=5124

answered on Stack Overflow Aug 7, 2013 by Richard Cook
1

This looks like a permission problem. I suggest running processMonitor to determine what permissions are needed.

answered on Stack Overflow Aug 6, 2013 by Mike
1

use NPOI to read and write excel..it's free and open source

for exapmle

using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;

//.....

private void button1_Click(object sender, EventArgs e)
{
    HSSFWorkbook hssfwb;
    using (FileStream file = new FileStream(@"c:\test.xls", FileMode.Open, FileAccess.Read))
    {
        hssfwb= new HSSFWorkbook(file);
    }

    ISheet sheet = hssfwb.GetSheet("Arkusz1");
    for (int row = 0; row <= sheet.LastRowNum; row++)
    {
        if (sheet.GetRow(row) != null) //null is when the row only contains empty cells 
        {
            MessageBox.Show(string.Format("Row {0} = {1}", row, sheet.GetRow(row).GetCell(0).StringCellValue));
        }
    }
}  

see this Stackoverflow question

answered on Stack Overflow Aug 7, 2013 by sangram parmar • edited May 23, 2017 by Community
0

Use this

create a user in admin group

add this user details in web config like below

<system.web>
   <identity impersonate="true"
    userName="User Name"
    password="Password" />
    `enter code here`</system.web>

restart the IIS and check again

-tony-

answered on Stack Overflow Dec 10, 2013 by Tony
0

Came across this issue two days back, spent whole complete two days, So I found that I need to give the access to IUSR user group at DCOMCNFG --> My Computer Properties --> Com Security --> Launch and Activation Permissions --> Edit defaults and give all rights to IUSR.

hope it will help someone....

answered on Stack Overflow Apr 7, 2017 by harshal H
0

If you are trying to configure this on 64bit, you have to do your DCOMconfig configuration (see other answers above) in:

C:\WINDOWS\SysWOW64>mmc comexp.msc /32

according to Setting Process-Wide Security Using DCOMCNFG.

After this, I was able to configure this for IIS_IUSRS without administrator privileges.

answered on Stack Overflow Jan 26, 2021 by Jan • edited Jan 29, 2021 by Greenonline

User contributions licensed under CC BY-SA 3.0