Search code examples
asp.netpermissionsoledb

ASP.NET OleDB permissions error


I'm uploading an Excel file and then reading data using oledb connection in asp.net but I'm getting the following error:

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.

Dim ocmd As New OleDbCommand("select * from [Sheet1$]", conn)

Line 12: conn.Open() Line 13: Dim odr As OleDbDataReader = ocmd.ExecuteReader()

conn.open() line is red highlighted for error.

The excel file is uploaded successfully and present in the folder.


Solution

  • What does your file upload logic look like? If you're using a FileStream, make sure you're properly closing the stream before trying to use OleDb... if you don't close the stream, the file will remain locked.

    Otherwise, make sure that you don't have the uploaded file currently open in Excel..