jeremycronan
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.InteropServ ices.COMEx ception: Exception from HRESULT: 0x800A03EC
Source Error:
Line 324: If File.Exists(source) Then
Line 325: 'Get Existing Workbook
Line 326: oldwb = excelapp.Workbooks.Open(so urce)
Line 327:
Line 328: 'Copy Current Worksheets to new Workbook
Source File: C:\inetpub\wwwroot\MondayR eport\App_ Code\Repor tGenerator .vb Line: 326
Stack Trace:
[COMException (0x800a03ec): Exception from HRESULT: 0x800A03EC]
Microsoft.Office.Interop.E xcel.Workb ooks.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.Merge Excel(List `1 list, String outputPath, DateTime reportDate, DateTime fromDate, DateTime thruDate) in C:\inetpub\wwwroot\MondayR eport\App_ Code\Repor tGenerator .vb:326
ReportGeneratorClass.Gener ateReports (DateTime reportDate, DateTime fromDate, DateTime thruDate, String reportType) in C:\inetpub\wwwroot\MondayR eport\App_ Code\Repor tGenerator .vb:107
ReportGenerator.btnRunRepo rts_Click( Object sender, EventArgs e) in C:\inetpub\wwwroot\MondayR eport\Repo rtGenerato r.aspx.vb: 50
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +115
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +140
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +29
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +2981
I've tried with Type.Missing in the optional parameter fields and get same problem. Code is attached
Exception Details: System.Runtime.InteropServ
Source Error:
Line 324: If File.Exists(source) Then
Line 325: 'Get Existing Workbook
Line 326: oldwb = excelapp.Workbooks.Open(so
Line 327:
Line 328: 'Copy Current Worksheets to new Workbook
Source File: C:\inetpub\wwwroot\MondayR
Stack Trace:
[COMException (0x800a03ec): Exception from HRESULT: 0x800A03EC]
Microsoft.Office.Interop.E
ReportGeneratorClass.Merge
ReportGeneratorClass.Gener
ReportGenerator.btnRunRepo
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
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
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?
ASKER
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\N ewFile.XLS ")
And see if the file is created in that folder
Dim wb As Excel.Workbook = excelapp.Workbooks.Add()
wb.SaveAs("THEFOLDERPATH\N
And see if the file is created in that folder
ASKER
Throws exception at Save As now
ASKER
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
ASKER
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
Since your said everythin is alright, we also can try to run your exe outside de ASP.NeT application and see if works
ASKER
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.OL EDB.4.0;Da ta Source=C:\YOURPATH\YOURFIL E.XLS;Exte nded 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()
Try This
Dim strConn As String
Dim oConn As New OleDbConnection()
strConn = "Provider=Microsoft.Jet.OL
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()
ASKER
Can't do this because need to copy Formatting of the existing Worksheets into the new worksheet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you sure you have read rights in the folder of the file you are trying to open?