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.
我有一个ASP.NET项目。我正在连接到数据库,然后关闭并处理连接对象。但是当有人进入我的网站时,MS Access会创建一个临时的dbname.ldb。当我想从我的服务器下载我的原始mdb文件时,它将不允许我访问mdb文件。如果服务器中有ldb文件,我什么也做不了。它锁定mdb文件,我无法移动它。所以有什么问题?我打开连接并关闭它。那么为什么这个ldb文件在连接关闭后不会自行删除。
6 个解决方案
#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.
如果脚本在关闭之前产生任何类型的错误,则可以保持连接打开。使用自定义错误500页检查脚本,该页面在文本文件中记录错误,您将看到是否是这种情况。无论如何,ldb文件没有危险,所以你可以创建一个脚本来每天删除一次。这是使用MS Access处理Web应用程序的缺点之一。尝试迁移到MSSQL,如果可以,或者到MySQL,最后可以从.NET或经典ASP使用ADO或ADO.NET与适当的驱动程序没有问题。
#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).
IIS中的Web应用程序通过连接池保持连接打开。如果在IIS设置为终止Web应用程序的时间内没有其他连接,或者您可以重新启动应用程序(并在任何人进入之前复制该文件),IIS应用程序最终将关闭。
That's just one reason Access is not a good choice of database for this kind of application.
这只是一个原因,Access对于这种应用程序来说不是一个很好的数据库选择。
#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.
.ldb文件是.mdb Access数据库的锁定文件。每次打开数据库时,Jet引擎都会创建锁定文件,并在有人连接时保持打开状态。一旦没有其他客户端连接到数据库,Jet将删除锁定文件。
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.
或者,您可以查看此CodeProject文章:在ASP.NET Web应用程序中查找“泄露”数据库连接。
#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.
您还可能需要考虑连接池 - 当您关闭连接时,c#实际上将其打开一段时间(30秒?60秒?),然后才真正关闭它,以防它可以重复使用。这可能是一个问题。
#5
One hacky workaround to remove the .ldb file is to do the following:
删除.ldb文件的一个hacky解决方法是执行以下操作:
- 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.
制作访问数据库的副本
删除原始访问数据库
删除.ldb文件
将访问数据库的副本重命名为原始数据库的名称。
#6
You need to Call GC.Collect() after Close and Dispose the Connection Object :)
你需要在关闭和处理连接对象后调用GC.Collect():)
#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.
如果脚本在关闭之前产生任何类型的错误,则可以保持连接打开。使用自定义错误500页检查脚本,该页面在文本文件中记录错误,您将看到是否是这种情况。无论如何,ldb文件没有危险,所以你可以创建一个脚本来每天删除一次。这是使用MS Access处理Web应用程序的缺点之一。尝试迁移到MSSQL,如果可以,或者到MySQL,最后可以从.NET或经典ASP使用ADO或ADO.NET与适当的驱动程序没有问题。
#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).
IIS中的Web应用程序通过连接池保持连接打开。如果在IIS设置为终止Web应用程序的时间内没有其他连接,或者您可以重新启动应用程序(并在任何人进入之前复制该文件),IIS应用程序最终将关闭。
That's just one reason Access is not a good choice of database for this kind of application.
这只是一个原因,Access对于这种应用程序来说不是一个很好的数据库选择。
#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.
.ldb文件是.mdb Access数据库的锁定文件。每次打开数据库时,Jet引擎都会创建锁定文件,并在有人连接时保持打开状态。一旦没有其他客户端连接到数据库,Jet将删除锁定文件。
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.
或者,您可以查看此CodeProject文章:在ASP.NET Web应用程序中查找“泄露”数据库连接。
#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.
您还可能需要考虑连接池 - 当您关闭连接时,c#实际上将其打开一段时间(30秒?60秒?),然后才真正关闭它,以防它可以重复使用。这可能是一个问题。
#5
One hacky workaround to remove the .ldb file is to do the following:
删除.ldb文件的一个hacky解决方法是执行以下操作:
- 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.
制作访问数据库的副本
删除原始访问数据库
删除.ldb文件
将访问数据库的副本重命名为原始数据库的名称。
#6
You need to Call GC.Collect() after Close and Dispose the Connection Object :)
你需要在关闭和处理连接对象后调用GC.Collect():)