windows 办公自动化DCOM故障

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1688853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:24:16  来源:igfitidea点击:

DCOM Failure of Office Automation

c#windowsms-officedcom

提问by Eric Ness

I developed a C# program that pulls data from a SQL Server database and then generates Word documents which include the data. I've set the program up to run as part of an SSIS job on a Windows Server 2003 box. The program runs as user SQLSVC which doesn't have administrative privileges. When I log in as SQLSVC and run the program it executes correctly. However, when the program is run automatically as an SSIS job it freezes at the following line of code

我开发了一个 C# 程序,它从 SQL Server 数据库中提取数据,然后生成包含数据的 Word 文档。我已将程序设置为在 Windows Server 2003 机器上作为 SSIS 作业的一部分运行。该程序以没有管理权限的用户 SQLSVC 身份运行。当我以 SQLSVC 身份登录并运行程序时,它会正确执行。但是,当程序作为 SSIS 作业自动运行时,它会在以下代码行冻结

Microsoft.Office.Interop.Word.Application word =
    new Microsoft.Office.Interop.Word.Application();

When I kill the process forcibly, the following error message is generated.

当我强行杀死进程时,会生成以下错误消息。

Error Message: System.Runtime.InteropServices.COMException (0x80080005):
Retrieving the COM class factory for component
with CLSID {000209FF-0000-0000-C000-000000000046}
failed due to the following error: 80080005.
   at IepGlance.Program.CreateNewIepFiles(Dictionary`2
       iepDictionary, EasyIepDataContext dbContext)
   at IepGlance.Program.Main(String[] args)

As far as I can figure out the problem is with DCOM permissions. I've used dcomcnfg to add all possible DCOM permissions to user SQLSVC, but this hasn't helped. Are there any other possible solutions?

据我所知,问题出在 DCOM 权限上。我已经使用 dcomcnfg 向用户 SQLSVC 添加了所有可能的 DCOM 权限,但这并没有帮助。还有其他可能的解决方案吗?

回答by Juny Eldo

Run program "dcomcnfg -32". ( You cant find the word and excel components if it runs under 64bit) Go to "Console Root/Component Services/Computer/My Computer/DCOM Config/" Look up Microsoft Word and Excel and choose properties. Go to Security and select "Customize" under "Configuration Permissions. (If needed you might want to change the other permissions as well, but I didn't need to) Add "IIS_IUSRS" and give it "Full Control". Now go to "Identity" and select "The interactive user".

运行程序“dcomcnfg -32”。(如果在 64 位下运行,则找不到 word 和 excel 组件) 转到“控制台根目录/组件服务/计算机/我的电脑/DCOM 配置/”查找 Microsoft Word 和 Excel 并选择属性。转到安全并选择“配置权限”下的“自定义”。(如果需要,您可能还想更改其他权限,但我不需要)添加“IIS_IUSRS”并赋予它“完全控制”。现在转到“身份”并选择“交互式用户”。

回答by Jay Riggs

Couple of things here.

这里有几件事。

First, this thread on SOmay help.

首先,SO 上的这个线程可能会有所帮助。

Second, Microsoft warnsthat 'complications' may arise when you automate Office through an unattended process. Here's the punchline (bolded in the original):

其次,Microsoft 警告说,当您通过无人值守的过程自动化 Office 时,可能会出现“并发症”。这是重点(在原文中加粗):

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Microsoft 当前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)自动化 Microsoft Office 应用程序,因为 Office 可能表现出不稳定的行为和/或在此环境中运行 Office 时出现死锁。

The linked article discusses workarounds.

链接的文章讨论了解决方法。

回答by Glenn Ferrie

It depends whether you are on a 64-bit machine and if you are 32-bit Office or 64-bit office, but in either scenario you need to go into the Admin Tools > Component Services and under DCOM config you need to find 'Microsoft Word 97 - 2003 Document', and then set the 'identity' to the user that is running your app pool. or simply disable the security on it.

这取决于您使用的是 64 位计算机,还是 32 位 Office 或 64 位办公室,但在任何一种情况下,您都需要进入管理工具 > 组件服务,在 DCOM 配置下,您需要找到“Microsoft Word 97 - 2003 文档”,然后将“身份”设置为运行您的应用程序池的用户。或者干脆禁用它的安全性。

If you are running a 64-bit server with 32-bit Office, you may have trouble finding this DCOM setting. You will need to run "MMC -32" from the command prompt to launch 32-bit MMC and then add 'Component Services' from the 'File > Add / Remove Snap-ins' menu.

如果您使用 32 位 Office 运行 64 位服务器,则可能无法找到此 DCOM 设置。您需要从命令提示符运行“MMC -32”以启动 32 位 MMC,然后从“文件 > 添加/删除管理单元”菜单中添加“组件服务”。

Hope this helped

希望这有帮助

回答by Anish

One point from my side, I was scheduling the batch job in one of our server and it was throwing the same error whereas it was running in my local.

从我的角度来看,我正在我们的一台服务器中安排批处理作业,但它在我的本地运行时抛出了相同的错误。

I tried all of the above steps but in my case actual scenario was different.

我尝试了上述所有步骤,但在我的情况下,实际情况有所不同。

Whenever schedule the batchjob, do not select the option [Run whether user is logged on or not] because this requires the admin access and if you are not, you are in problem.

无论何时安排批处理作业,都不要选择选项[无论用户是否登录都运行],因为这需要管理员访问权限,如果不是,则有问题。

enter image description here

在此处输入图片说明