ASP.NET Cannot create ActiveX component

I have a ASP.NET application that allows users to export their staff’s absences each month to Microsoft Excel. The application is currently generating the following exception

Exception: Cannot create ActiveX component.

with the following stack trace

System.Exception: Cannot create ActiveX component.
at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)
at HR.ManagerSummary.ExportToExcel() in H:DevelopmentpagecVisual Studio 2005ProjectsHRysnet2TimeManagerSummary.aspx.vb:line 935
at HR.ManagerSummary.btnExcel_Click(Object sender, EventArgs e) in H:DevelopmentpagecVisual Studio 2005ProjectsHRysnet2TimeManagerSummary.aspx.vb:line 891
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The code fails at the CreateObject line.

    'Create the Excel object
    Dim objXL As Object = CreateObject("Excel.Application") ' New Microsoft.Office.Interop.Excel.Application
    Dim objWB As Object = objXL.Workbooks.Add
    Dim objWS As Object = objWB.Worksheets(1)

I’ve set permission in DCOM Config for Microsoft Excel Application for the IUSR_ account but that has not resolved the issue. Any ideas would greatly be appreciated.

Cheers

James

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Following migration of our ASP.NET applications to new hardware, I investigated this issue further and came up with a solution.

To resolve the issue, open “Component Services” from Administrative Tools and navigate as follows:

  • Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application
  • Right click Microsoft Excel Application -> Properties -> Security tab
  • Click Customize for “Launch and Activation Permissions” -> Edit -> Add
  • Enter “NETWORK SERVICE”, click “Check Names”, click OK
  • Allow “Local Launch” and “Local Activation” for “NETWORK SERVICE” then click OK
  • Select Customize for “Access Permissions” -> Edit -> Add
  • Enter “NETWORK SERVICE”, click “Check Names”, click OK
  • Allow “Local Access” for for “NETWORK SERVICE” then click OK
  • Click OK

The ASP.NET application can now successfully create a Microsoft Excel worksheet containing the exported data.

Method 2

Did you registered the ActiveX on the server?

http://support.microsoft.com/kb/146219

Method 3

SpreadsheetGear for .NET will let you save xls and xlsx workbooks directly to a response stream with IWorkbook.SaveToStream. It is all safe managed C# code so there is no need to run anything as admin and you will not run into the problems that Excel COM Interop bring on an ASP.NET server.

You can see some simple ASP.NET Excel Reporting samples (C# and VB) using SpreadsheetGear here and download the free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x