views:

2607

answers:

6

Hello,

I am trying to edit a word document from VB.NET using for the most part this code:

How to automate Word from Visual Basic .NET to create a new document http://support.microsoft.com/kb/316383

It works fine on my machine but when i publish to the server i get the following error.

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005.

The actual error happens when i try to just create a word application object

 Dim oWord As New Word.Application

Using Visual Studio 2008 and VB.NET 3.5. I made a reference to the "Microsoft Word 10.0 Object Library" and i see Interop.Word.dll file in the bin directory.

Using MS Office 2003 on development machine and Windows Server 2003

Still fairly new to .NET and don't have much knowledge about window server, but "UnauthorizedAccessException" sounds like a permission issue. I'm wondering if someone could point me in the right direction on what i might need to do to give my little application access to use word.

Thank you so much for your time.

+1  A: 

It definitely sounds like a permissions problem. Are you running your code in a windows service? The service normally runs as Local System, which may not have permission to access the Word object model. Additionally, if word is already running using the credentials of some other user then your program may not be able to access it via COM using different credentials. The office applications tend to be single instance which seems to exacerbate this problem.

1800 INFORMATION
Interesting enough when i logged into the system and ran Word it ran the installer. I guess no one ran word before on this user. It didn't solve my problem but i'm wondering even w/o the permission issue if that would have stopped it from working. No my code is a Web Application. While this is a small rarely used app i never considered what would happen if two people tried to run it at the same time.Thanks for that input.Is there a way to see if some one other is accessing the COM object? I'm pretty sure nothing else is but i wouldn't even know where to check that.
TheDPQ
The Web application is running as what user? In IIS 7 for instance, the application pool will run as local system which will probably have the same problem.
1800 INFORMATION
Again excuse my ignorance but is "Network Service" what you are talking about? It's the identity the application pool is set to use.
TheDPQ
yes, there are two well know userids that services commonly run as. Local system is a low privileged userid that is normally used by services that do not provide services to the network. Network service is used by services that do
1800 INFORMATION
You could try to configure the application pool to use your credentials instead
1800 INFORMATION
I added <identity impersonate="true"/> to the webconfig and then added myself to the MS Word Document DCOM and i get the same 80080005 error i mentioned below. I found the 'Application ID' in DCOM for Word Application ID is {00020906-00000-0000-C000-000000000046} but the error i'm getting says CLSID 000209FF-0000-0000-C000-000000000046 i wonder if that is relevant. Thank you again for your help i've learned a lot even if my problem is still there. :D
TheDPQ
I logged into the server as myself, ran the web app, and it popped up some weird windows live thing and when i hit 'continue' it actually did launch word but gave me the ASP.NET error "The Add method or property is not available because the license to use this application has expired". Haha the office on the server has never been activated... and i just realized i have word 2002 (MS 10) and the server has 2003 (MS 11).... i'll look into both those issues.
TheDPQ
A: 

It sounds like you may have a permission issue in DCOM. Try editing the Word permissions in DCOM config.

Miyagi Coder
Found a few people referencing http://blog.crowe.co.nz/archive/2006/03/02/589.aspx but its for excel. Didn't help, the error is the same but the error number did change changed to: 80080005.System.Runtime.InteropServices.COMException instead of System.UnauthorizedAccessException
TheDPQ
A: 

Hello,

I was experiencing the same issue and the problem area I found was "security configuration for Microsoft Word in DCOM". On the following link you can find a step by step guide to know how to config components in DCOM, repeate these steps for WORD, and your problem will be solved.

http://www.biocompsystems.com/%5Fpublic/DCOMConfigurationStepbyStepForXP.doc

Thanks, Sushil Jinder

jinder sushil
A: 

yes.. the problem is of permission

you just need to enable impersonation.

Go in your web.config file and int the section set

this worked for me!

Hope this is usefule.

--Manish Thakkar

Manish
Hi Manish,Can you please give more description about how to set this impersonation? I am facing the same problem.
Shekhar
A: 

I had the same issue on Windows 2008 R2. Ended up using this post: http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/65a355ce-49c1-47f1-8c12-d9cf5f23c53e

and then changing the impersonation identity user in web.config to another user to solve it.

I'm sure there is a combination of solutions.

tunc