Search code examples
asp.netvb.netoledb

System.AccessViolationException: Attempted to read or write protected memory


I am getting the following error while trying to read from an excel file in my server.

"System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

The code runs smoothly in localhost, but the error comes when i host it online.

I am unable to post the stacktrace as i do not get error everytime, but the executions stops at the line "objConn.open". The page just says loading... and nothing happens.

Here is my code block :

     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$]"

EDIT : The page keeps saying loading ... it wont stop loading...


Solution

  • Most probable reason is, your user account on the machine does not have sufficient access to perform this operation. On localhost, you might be using the Administrator account and it is not so in the live machine.