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:WindowsSysWOW64configsystemprofile”
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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
- Make sure that you have Office runtime installed on the server.
- 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
Method 2
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.
Method 3
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.
Method 4
- give the read / write permission to the IIS user or group users
-
Start -> run -> inetmgr
enable the ASP.NET authentication for your default website
3.
For 64-bit (x64), create this folder:
C:WindowsSysWOW64configsystemprofileDesktop
For 32-bit (x86), create this folder:
C:WindowsSystem32configsystemprofileDesktop
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.
Method 5
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:WindowsSysWOW64configsystemprofileDesktop
For 32 bit applications : C:WindowsSystem32configsystemprofileDesktop
* 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.
Method 6
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!
Method 7
try to do the following:
- Make sure Office interop assemblies are installed.
- Check the version of the assemblies on development and production.
- Create Desktop folder under systemprofile.
- set the DCOM security explicitly for the service user.
you can find more details here
Method 8
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.
Method 9
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
Method 10
This looks like a permission problem. I suggest running processMonitor to determine what permissions are needed.
Method 11
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
Method 12
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….
Method 13
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-
Method 14
If you are trying to configure this on 64bit, you have to do your DCOMconfig configuration (see other answers above) in:
C:WINDOWSSysWOW64>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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0