OLEDB连接在调试中工作但不在浏览器中工作 - 创建文件失败

时间:2018-01-12 15:24:33

标签: vb.net oledb oledbconnection

我正在将网站从服务器2003迁移到服务器2012。 当我通过Visual Studios(2010)在调试中打开它时,其中一个有问题的页面有效,但当我只是通过浏览器访问页面时(甚至通过服务器在本地访问),它不起作用。

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()

代码应该输出一个excel文件但是当我在浏览器中运行时,我收到以下消息。

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()

我已经尝试过以下方法: 我在应用程序池中启用了32位应用程序。 我对DefaultAppPool&amp ;;提供了完全的读写访问权限。网络服务帐户。

一些补充说明:我的评论是对原始代码的修改。在旧服务器上不需要@但是当我将其添加到此代码以修复路径问题时,它会导致OLEDB调用出现问题。

0 个答案:

没有答案