简体   繁体   English

Office自动化的DCOM故障

[英]DCOM Failure of Office Automation

I developed a C# program that pulls data from a SQL Server database and then generates Word documents which include the data. 我开发了一个C#程序,它从SQL Server数据库中提取数据,然后生成包含数据的Word文档。 I've set the program up to run as part of an SSIS job on a Windows Server 2003 box. 我已将程序设置为在Windows Server 2003框上作为SSIS作业的一部分运行。 The program runs as user SQLSVC which doesn't have administrative privileges. 该程序以用户SQLSVC运行,该用户没有管理权限。 When I log in as SQLSVC and run the program it executes correctly. 当我以SQLSVC身份登录并运行程序时,它会正确执行。 However, when the program is run automatically as an SSIS job it freezes at the following line of code 但是,当程序作为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. 据我所知,问题在于DCOM权限。 I've used dcomcnfg to add all possible DCOM permissions to user SQLSVC, but this hasn't helped. 我已经使用dcomcnfg将所有可能的DCOM权限添加到用户SQLSVC,但这没有帮助。 Are there any other possible solutions? 还有其他可能的解决方案吗?

Run program "dcomcnfg -32". 运行程序“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. (如果在64位下运行,则无法找到单词和excel组件)转到“控制台根目录/组件服务/计算机/我的电脑/ DCOM配置/”查找Microsoft Word和Excel并选择属性。 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". 转到安全性并选择“配置权限”下的“自定义”。(如果需要,您可能还想更改其他权限,但我不需要)添加“IIS_IUSRS”并将其命名为“完全控制”。现在转到“身份”并选择“交互式用户”。

Couple of things here. 这里有几件事。

First, this thread on SO may help. 首先, SO上的这个主题可能有所帮助。

Second, Microsoft warns that 'complications' may arise when you automate Office through an unattended process. 其次, 微软警告说 ,当您通过无人值守的流程自动化Office时,可能会出现“并发症”。 Here's the punchline (bolded in the original): 这是妙语(原文中加粗):

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. 链接的文章讨论了变通方法。

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. 这取决于您是否在64位计算机上,如果您是32位Office或64位办公室,但在任何一种情况下,您都需要进入管理工具>组件服务,在DCOM配置下,您需要找到'Microsoft Word 97 - 2003 Document',然后将'identity'设置为运行应用程序池的用户。 or simply disable the security on it. 或者只是禁用它的安全性。

If you are running a 64-bit server with 32-bit Office, you may have trouble finding this DCOM setting. 如果您运行的是具有32位Office的64位服务器,则可能无法找到此DCOM设置。 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. 您需要从命令提示符运行“MMC -32”以启动32位MMC,然后从“文件”>“添加/删除管理单元”菜单中添加“组件服务”。

Hope this helped 希望这有帮助

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. 每当安排批量工作时,不要选择[运行用户是否登录]选项,因为这需要管理员访问权限,如果不是,则表示您遇到问题。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM