2

I have a ASP.NET application which uses Microsoft intrope assemblies to read, write and modify excel files and it uses Excel 2013 on server machine. Application works fine if i am logged in to server machine as administrator but when i am logged out the application is unable to to initialize excel application. Here is the exception.

System.Runtime.InteropServices.COMException (0x8000401A)

Application is running on Windows Server 2008R2 with MS Excel 2013 32-bit I am not being able to figure out the reason of this behavior. Is this about COM objects security options or it has something to do with IIS permissions?

AddyProg
  • 2,960
  • 13
  • 59
  • 110

2 Answers2

5

The InteropServices class opens an (invisible) Excel instance to get its work done. Excel cannot run as a Windows service and needs to be instanciated by a logged on user.

"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." See this page for more information: Office support: Considerations for server-side Automation of Office

If you still want to keep the interop service, try change it to run as an interactive user:

  • Open Component Services (Start -> Run -> MMC comexp.msc /32)
  • Find Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application
  • Right click, choose properties
  • Go to the Identity tab and choose Interactive user
  • If this is not working, you can try to manually enter the user credentials

Of course, you could also switch to another framework to read the file. SO: How to read an excel file in C# without using Microsoft.Office.Interop.Excel libraries

Community
  • 1
  • 1
Physikbuddha
  • 1,652
  • 1
  • 15
  • 30
  • currently I am facing this issue with Interactive User, I tried using Administrator credentials it solves this problem but then VBA addins don't work. – AddyProg May 07 '15 at 09:00
  • @AdilWaqar Are these add-ins integrated into your ASP.NET solution, or do you need them while you are 'actually working' with Excel? – Physikbuddha May 07 '15 at 09:11
  • no addin is not integrated in ASP.NET app, its basically installed on server and run with Excel. – AddyProg May 07 '15 at 09:17
  • @AdilWaqar Try creating the folder: "C:\Windows\SysWOW64\config\systemprofile\Desktop" Can't test it with your application, but it has solved a lot of problems with the Interop classes. – Physikbuddha May 07 '15 at 09:28
  • Both AppData and Desktop folders are there in SysWOW64 and system32 – AddyProg May 07 '15 at 09:31
  • @AdilWaqar I've updated my post with information from the official Office support center. It may help you to decide on how to deal with server-side Office integration. – Physikbuddha May 07 '15 at 09:39
0

I had the same problem after migrating from 2008r2 to 2012. My solution:

  • Find Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application
  • Right click, choose properties
  • Go to the Identity tab and choose This user (input user & password)
vich
  • 11,836
  • 13
  • 49
  • 66