3
votes

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());
        }
    }
2
Does your server have Office installed or have you published the Libs with the app?Sorceri
It's a bit unclear: where does this .NET code run? As part of an ASP.NET web page? On the server side? Is Excel installed on the server? Do you know that Office Automation isn't supported for server-side code?Avner Shahar-Kashtan
Also, are you sure you aren't mixing up the server-side and client-side models in your application? If the code opens Excel on your server, than a user accessing that webpage won't see it, it's not on his machine.Avner Shahar-Kashtan
you need to make sure that the target server has the installed / correct version of the Assembly's also do you copy the local assembly's or have those installed in the GAC on the target ServerMethodMan

2 Answers

5
votes
  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.
2
votes

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.