【问题标题】:System.AccessViolationException: Attempted to read or write protected memorySystem.AccessViolationException:试图读取或写入受保护的内存
【发布时间】:2012-09-21 00:39:56
【问题描述】:

我在尝试读取服务器中的 Excel 文件时遇到以下错误。

“System.AccessViolationException:试图读取或写入受保护的内存。这通常表明其他内存已损坏。”

代码在 localhost 中运行流畅,但在线托管时出现错误。

我无法发布堆栈跟踪,因为我不会每次都出错,但执行会在 "objConn.open" 行停止。页面只是说正在加载......但没有任何反应。

这是我的代码块:

     fuGroupAttributes.SaveAs(IO.Path.Combine(Server.MapPath("~/Admin/SpecificationExcels"), lblParentId.Text.Trim & IO.Path.GetExtension(fuGroupAttributes.FileName)))
'saving the excel file from the fileUploader

                           Dim path As String = Server.MapPath("~/Admin/SpecificationExcels/" & lblParentId.Text.Trim & IO.Path.GetExtension(fuGroupAttributes.FileName))
'getting the file path from the server


                           Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=Excel 12.0;"
                           Dim objConn As New OleDbConnection(connectionString)
                           **objConn.Open()** 'this is where i am getting the error.
                           Dim strConString As String = "SELECT * FROM [Sheet1$]"

编辑:页面一直说加载...它不会停止加载...

【问题讨论】:

    标签: asp.net vb.net oledb


    【解决方案1】:

    最可能的原因是,您机器上的用户帐户没有足够的权限来执行此操作。在 localhost 上,您可能使用的是管理员帐户,而在 live 机器中并非如此。

    【讨论】:

    • 您在谈论访问文件系统的权限。我相信你肯定有这个,因为如果你没有,你可能会得到不同类型的错误,(文件访问异常)。我想说的是,您要么没有权限使用 oledb 驱动程序进行 excel。这有几个原因,其中之一是 - 在通常共享的 Web 服务器上,您的 Web 应用程序未在“完全信任环境”中运行 - 我建议您在 google 上搜索该术语,您会发现一些有用的提示
    • 我尝试将连接字符串更改为Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Extended Properties=""Excel 8.0;HDR=YES;""",现在我收到此错误System.Data.OleDb.OleDbException: The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data.
    • 因为你可以在本地打开文件,所以连接字符串和代码绝对没有问题。问题在于您的 Web 服务器 (IIS) 正在模拟的身份。如果可能,请尝试在另一台 Web 服务器上执行相同的代码。
    • 哦,我想我可能明白了,请在您上传文件后检查您的文件是否为只读文件。如果是这样,你会得到这个错误
    • 不,在服务器本身上检查它,如果它是只读的。尝试从 FTP 上传文件并使用 ftp 客户端本身将权限设置为 777。(大多数 ftp 客户端确实具有此功能)并让我知道它是否解决了问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    相关资源
    最近更新 更多