Live Chat Icon For mobile
Live Chat Icon

Why do I get ‘Could not lock file’ and ‘cannot open file’ exceptions when bound to a mdb file?

Platform: ASP.NET| Category: DataGrid

You could get this error for the following reasons:

  1. When you create a project afresh, add a new OleDbDataAdapter to the form and link to the mdb file, the connection object created in the process will keep an open connection to the mdb file which is what will cause the above ‘Could not lock file’ exception during runtime. To workaround this, go to ‘Server Explorer’ in your IDE, right click on the corresponding ‘Connection entry’ and select Close Connection. This should fix the problem.
  2. The ‘cannot open file’ exception could then occur if you have not provided enough permissions on the mdb file to allow the .net runtime to lock it. To ensure enough permissions, open it’s properties, select the Security tab and add a ‘Everyone’ account granting ‘Full Control’ to it. This should let the .net runtime lock the file.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.