opening excel error: System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID

2

I have a C# .net web app. I want a user to click a button on a webpage, the server to open an excel spreadsheet and write data to it, and the user to save the document. This works locally using Visual Studio 2010 and Office 2010. On my server, however, I get this error:

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

I have researched and found a ton of answers stating to open dcomconfig and add the user with permissions to Microsoft Excel Application. My site is set to passthrough security so I added myself; I am an admin on the server, so I ensured Admins had access; I also added the App Pool default of Network Service; also ASP.NET Machine Account; and, just in case, added the account the app uses when connecting to the database. I still get the exact same error.

My server is 64 bit, Office 2007, IIS 7.

My code is:

    {
        try
        {
            Excel.Application xXL = null;
            Excel.Workbook xWB = null;
            Excel.Worksheet xSheet = null;
            xXL = new Excel.Application();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
c#
.net
excel
asked on Stack Overflow Feb 5, 2013 by user2044518 • edited Feb 5, 2013 by Bart

2 Answers

4
  1. In DCOMCNFG, right click on the My Computer and select properties.
  2. Go to Component /MyComputer/DCOMConfig
  3. Go to Microsoft Excel Application property Security
  4. In launch and Activation Permissions, click "Custamize" and add Network Service to it and give it "Local launch" and "Local Activation" permission. give same As Acess Permissions and cofiguration Permissions Press OK and thats it. i can run my application now.
answered on Stack Overflow Nov 6, 2015 by Viral Prajapati
2

Office automation - the usage of these Excel.Application and Excel.Workbook objects - is not recommended and not supported by Microsoft. Look:

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.

This means that even if yo sort out your server-side/client-side issues, you're still playing with fire, since some scenarios might work, others won't, and others will sometimes work and sometimes cause your process to hang because Excel attempts to open a pop-up notification when there isn't a console user logged onto the server. Trust me, don't do it.

The link I provided lists several alternatives to what you're trying to do, but assuming you're planning on building relatively simple Excel sheets for your user, you're better off just creating a CSV file and sending that back to the user with the appropriate header (something like Response.ContentType="application/vnd.ms-excel") so that the returned data will be opened by Excel by default. You can see more answers to that question here.

answered on Stack Overflow Feb 5, 2013 by Avner Shahar-Kashtan • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0