How Can I Remove Access Db's temporary ldb file

22,929

Solution 1

The connection can be left open if the scripts produces an error of any kind before to close it. Check the scripts with a customized error 500 page that logs in a text file the errors and you will see if this is the case. Anyway the ldb file is not dangerous so you can create a script to remove them once a day or so. This is one of the drawbacks about working web applications with MS Access. Try to migrate to MSSQL if you can or to MySQL, this last can be used from .NET or classic ASP with no problem with ADO or ADO.NET with the appropiate driver.

Solution 2

Your web application within IIS is keeping the connection open with connection pooling. The IIS application will eventually close if there are no further connections within the time IIS is set to terminate your web application or you can restart the application (and copy the file before anyone gets in).

That's just one reason Access is not a good choice of database for this kind of application.

Solution 3

You also may want to consider connection pooling - when you close a connection, c# actually keeps it open for a while (30 secs? 60 secs?) before really closing it, in case it can be re-used. This may be an issue.

Solution 4

The .ldb file is the lock file for .mdb Access databases. Every time you open a database, the Jet engine will create the lock file and keep it open for as long as someone is connected. Once there are no other clients connected to the database, Jet removes the lock file.

So you are seeing the lock file for one of two reasons:

  • There is an open connection.
  • There is a broken connection, and the lock file could not be removed.

If checking the error logs of your server doesn't give you anything, try to log all database accesses from within your application to a file: append information about the time, connection and other useful debug information.
That could be an easy way to quickly debug the problem and see where and when the connection is left open.

Alternatively, you could have a look at this CodeProject article: Find "Leaked" Database Connections in ASP.NET Web Applications.

Solution 5

One hacky workaround to remove the .ldb file is to do the following:

  • Make a copy of the access database
  • Delete the original access database
  • Delete the .ldb file
  • Rename the copy of the access database to the name of the original one.
Share:
22,929
Ibrahim AKGUN
Author by

Ibrahim AKGUN

I am a computer programmer.

Updated on July 17, 2022

Comments

  • Ibrahim AKGUN
    Ibrahim AKGUN almost 2 years

    I have an ASP.NET Project. I am connecting to the DB and then closing and disposing of the connection object. But when anyone enters my site, MS Access creates a temporary dbname.ldb. When I want to download my original mdb file from my server it won't let me access the mdb file. I can't do anything if there is ldb file in server. It's locking mdb file and I can't move it. So what's the problem? I am opening connection and closing it. So why this ldb file not deleting itself after the connection is closed.

  • Chris
    Chris almost 15 years
    Another option in a similar league to access is Sqlite, if you want single-file databases. Its much less buggy than access.
  • David-W-Fenton
    David-W-Fenton almost 15 years
    @Chris: Access is not buggy. If people use it inappropriately (as I believe using it for anything but the most trivial website is) they shouldn't be surprised when things work poorly. But this is not because Access is buggy, but because it's being misused.
  • Dai
    Dai almost 6 years
    Calling GC.Collect() will not release any database locks. An explicit call to Dispose() (including using blocks) is all you need - calls to Close() are entirely superfluous as Close and Dispose do the exact same thing.