views:

1870

answers:

5

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.

+1  A: 

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.

backslash17
Another option in a similar league to access is Sqlite, if you want single-file databases. Its much less buggy than access.
Chris
@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.
David-W-Fenton
A: 

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.

backslash17
bad connection makes posting duplicate answer!
backslash17
+2  A: 

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.

Renaud Bompuis
+2  A: 

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.

Chris
+2  A: 

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.

Cade Roux