“正在为组件检索 COM 类工厂.... 错误:80070005 访问被拒绝."(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED)) [英] "Retrieving the COM class factory for component.... error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
问题描述
我刚刚创建了一个简单的应用程序并托管在 IIS6.0 中.在代码中,我只是实例化 excel 对象.
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();
}
}
}
它给了我以下错误
"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)).
系统配置:
Windows Server 2008,64 位企业版.服务包 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) 在路径C:WindowsSysWOW64configsystemprofile"下创建桌面应用程序2) 在 DCOMCNFG 中为 Microsfot.EXcelApplicaiton 设置完全权限/控制3)杀死任务管理器中的所有excel实例
请在这方面帮助我,这只是示例应用程序,但在我原来的应用程序中主要是关于从/向 Excel 读取和写入数据.
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.
推荐答案
- 确保您在服务器上安装了 Office 运行时.
- 如果您使用的是 Windows Server 2008,那么使用办公互操作是一个冗长的配置,以下是步骤.
最好是移动到 Open XML 或者您可以配置如下
Better is to move to Open XML or you can configure as below
- 安装 MS Office Pro 最新版(我使用的是 2010 Pro)
- 创建用户 ExcelUser.为 WordUser 分配管理员组
- 转到计算机 -> 管理
- 使用以下选项添加用户
- 用户选项密码永不过期
- 密码不能更改
Com+ 配置
- 进入控制面板 -> 管理员 -> 组件服务 -> DCOM 配置
- 打开 Microsoft Word 97 - 2003 属性
- 一般 -> 身份验证级别:无
- 安全 -> 自定义所有 3 个权限以允许所有人
- 身份 -> 此用户 -> 使用 ExcelUser/password
- 启动 Excel 应用程序以确保一切正常
3.在 DCOM Config 中更改 Microsoft Excel 应用程序的安全设置.
3.Change the security settings of Microsoft Excel Application in DCOM Config.
控制面板 --> 管理工具 --> 组件服务 --> 计算机 --> myComputer --> DCOM 配置 --> Microsoft Excel 应用程序.
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
请参阅此处的帖子:创建 Excel 对象时出错 , 使用 COM 在 WCF 中操作 Excel
See the posts here: Error while creating Excel object , Excel manipulations in WCF using COM
这篇关于“正在为组件检索 COM 类工厂.... 错误:80070005 访问被拒绝."(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!