I am migrating a website from server 2003 to server 2012. One of the pages having problems works when I open it in debug via Visual Studios(2010) but doesn't work when I just access the page via browser (even locally through the server).
Dim fileName As String
Dim templateFileName As String
Dim MyConnection As System.Data.OleDb.OleDbConnection
'@ used to bypass pathing issue
templateFileName = "@" + Server.MapPath(".") + "\Product.xls"
fileName = "@" + Server.MapPath(".") + "\excel\Product_" + Request.UserHostAddress + ".xls"
If (System.IO.File.Exists(fileName) = True) Then
System.IO.File.Delete(fileName)
End If
If (System.IO.File.Exists(templateFileName) = True) Then
System.IO.File.Copy(templateFileName, fileName)
End If
'@ removed from path because OleDb doesn't like it.
templateFileName = Server.MapPath(".") + "\Product.xls"
fileName = Server.MapPath(".") + "\excel\Product_" + Request.UserHostAddress + ".xls"
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & fileName & "';Extended Properties=Excel 8.0;")
MyConnection.Open()
The code is supposed to output an excel file but when I run in browser, I get the following message.
Failure creating file.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Failure creating file.
Source Error: MyConnection.Open()
I already tried the following: I enabled 32-bit applications in the app pool. I gave full read-write access to DefaultAppPool & Network Service accounts.
Some additional notes: My ' comments were modifcations to the original code. @ wasn't needed on the old server but when I added it to this code to fix to pathing issue, it caused problems for the OLEDB call.