How Can I Remove Access Db's temporary ldb file

我与影子孤独终老i 提交于 2019-12-23 18:08:42

问题


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:


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.




回答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.




回答3:


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.




回答4:


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.




回答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.



回答6:


You need to Call GC.Collect() after Close and Dispose the Connection Object :)



来源:https://stackoverflow.com/questions/1015336/how-can-i-remove-access-dbs-temporary-ldb-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!