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.
Better is to move to Open XML or you can configure as below
Com+ Configuration
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
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.
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.
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:\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.
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!
try to do the following:
you can find more details here
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.
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.
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
This looks like a permission problem. I suggest running processMonitor to determine what permissions are needed.
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
Use this
<system.web>
<identity impersonate="true"
userName="User Name"
password="Password" />
`enter code here`</system.web>
-tony-
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....
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.
User contributions licensed under CC BY-SA 3.0