Link to home
Start Free TrialLog in
Avatar of jeremycronan
jeremycronanFlag for United States of America

asked on

Exception from HRESULT: 0x800A03EC on opening Excel Workbook in Server 2008

I have a VB.NET website that opens a group of Excel documents and merges them into one Excel document. It works fine when running from Visual Studio, but when we place it on the IIS Server, Windows Server 2008 with IIS 6.0, it gives the error

Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC

Source Error:


Line 324:            If File.Exists(source) Then
Line 325:                'Get Existing Workbook
Line 326:                oldwb = excelapp.Workbooks.Open(source)
Line 327:
Line 328:                'Copy Current Worksheets to new Workbook
 

Source File: C:\inetpub\wwwroot\MondayReport\App_Code\ReportGenerator.vb    Line: 326

Stack Trace:


[COMException (0x800a03ec): Exception from HRESULT: 0x800A03EC]
   Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
   ReportGeneratorClass.MergeExcel(List`1 list, String outputPath, DateTime reportDate, DateTime fromDate, DateTime thruDate) in C:\inetpub\wwwroot\MondayReport\App_Code\ReportGenerator.vb:326
   ReportGeneratorClass.GenerateReports(DateTime reportDate, DateTime fromDate, DateTime thruDate, String reportType) in C:\inetpub\wwwroot\MondayReport\App_Code\ReportGenerator.vb:107
   ReportGenerator.btnRunReports_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\MondayReport\ReportGenerator.aspx.vb:50
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

 
I've tried with Type.Missing in the optional parameter fields and get same problem. Code is attached
Dim source, destination As String
        destination = outputPath + "Weekly Report " + DateToString(reportDate) + ".xls"

        Dim excelapp As Excel.Application = New Excel.Application()

        'Hide Excel while using and don't display alerts
        excelapp.Visible = False
        excelapp.DisplayAlerts = False

        Dim wb As Excel.Workbook = excelapp.Workbooks.Add(Type.Missing)

        'Delete empty Worksheets created except for first one.
        Dim ws As Excel.Worksheet
        For i As Integer = wb.Worksheets.Count To 2 Step -1
            ws = DirectCast(wb.Worksheets.Item(i), Excel.Worksheet)
            ws.Delete()
        Next

        Dim oldwb As Excel.Workbook
        Dim oldws As Excel.Worksheet

        For Each r As Report In list
            source = r.Destination & r.FileName & r.FileExtension

            If File.Exists(source) Then
                'Get Existing Workbook
                oldwb = excelapp.Workbooks.Open(source)

                'Copy Current Worksheets to new Workbook
                For i As Integer = 1 To oldwb.Worksheets.Count
                    oldws = oldwb.Worksheets.Item(i)
                    oldws.Copy(Type.Missing, wb.Sheets.Item(wb.Sheets.Count))
                    ws = wb.Sheets.Item(wb.Sheets.Count)
                    ws.Name = r.FileName
                Next


            End If
        Next

Open in new window

Avatar of gamarrojgq
gamarrojgq

Hi,

Are you sure you have read rights in the folder of the file  you are trying to open?
Avatar of jeremycronan

ASKER

We have impersonate in the web.config to an account with admin privileges.
ok, but have you try to asign read/write rights to the ASP.Net Account?
Since it is Server 2008, I have read/write access to the folder where the Excel documents are to the Network Service user.
Ok, in your post you said that the problem is in line 326, just when the code try to OPEN a file, so, try to save the new xls document that you create before that line, jus after you DIM it

Dim wb As Excel.Workbook = excelapp.Workbooks.Add()
wb.SaveAs("THEFOLDERPATH\NewFile.XLS")

And see if the file is created in that folder
Throws exception at Save As now
How can I get ASP.NET to call an EXE that does what I need? I have the ProcessStartInfo and calling a Process, but when place in IIS on Windows 2008, doesn't do it. Both Impersonator and Network Service have full access to the exe
Ok, something is blocking your user from read/write that folder and to run EXE files, check in IIS in the application Permissions if the IIS_IUSR user have rights or anohter user related with ASP, and if not, grant the rights to that uses and try
The Application Pool is set to use a Domain User that has all of the right permissions and still not working
Ok, try to use another user and another folder, perhaps the actual folder/user have some issues that do not allow open/read XLS files, or some missing configurations in your web.config or machine.config

Since your said everythin is alright, we also can try to run your exe outside de ASP.NeT application and see if works
I can run the Console app by itself and works fine. It just doesn't work when calling from Web through IIS
Ok, lets take another approach, we can try to open the file with ADO.NET and see if allow you this way, if does perhaps something with EXCELi s the problem

Try This

        Dim strConn As String
        Dim oConn As New OleDbConnection()

        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\YOURPATH\YOURFILE.XLS;Extended Properties=Excel 8.0;"

        oConn.ConnectionString = strConn
        oConn.Open()

        Dim oCmd As New OleDbDataAdapter("SELECT * FROM [YOURSHEETNAME$]", oConn)
        Dim oDS As New DataSet()
        oCmd.Fill(oDS)

        Dim intRows As Integer
        intRows = oDS.Tables(0).Rows.Count
        oCmd.Dispose()
        oConn.Close()
Can't do this because need to copy Formatting of the existing Worksheets into the new worksheet
ASKER CERTIFIED SOLUTION
Avatar of jeremycronan
jeremycronan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial