最好在每次操作之后都将其关闭以更好地关闭Access DB,以便以后进行操作 [英] Is it better to better to close the access DB after every operation of keep it open for later operations

查看:49
本文介绍了最好在每次操作之后都将其关闭以更好地关闭Access DB,以便以后进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个VB.NET项目,该项目从Access DB文件中获取数据.我遇到的所有代码片段都将打开数据库,进行处理,然后为每个操作将其关闭.我目前在应用程序运行的整个过程中都打开了数据库,只有在应用程序退出时才关闭它.

I am working on a VB.NET project that grabs data from an Access DB file. All the code snipeets I have come across open the DB, do stuff and close it for each operation. I currently have the DB open for the entire time the application is running and only close it when the application exits.

我的问题是:为每个操作打开与数据库文件的连接,而不是在应用程序运行期间保持打开状态,是否有好处?

My question is: Is there a benefit to opening the connection to the DB file for each operation instead of keeping it open for the duration the application is running?

推荐答案

Jet/ACE数据库引擎没有任何好处.创建LDB文件(记录锁定文件)的成本非常高.您也许可以通过以独占方式打开文件(如果是单个用户)来避免这种情况,但是我的感觉是,以独占方式打开比打开多用户方式要慢.

There is no benefit with the Jet/ACE database engine. The cost of creating the LDB file (the record locking file) is very high. You could perhaps avoid that by opening the file exclusively (if it's a single user), but my sense is that opening exclusive is slower than opening multi-user.

关于打开和关闭连接的建议是基于一个假设,即数据库服务器位于连接的另一端.如果您考虑一下它是如何工作的,那么打开和关闭连接的成本非常小,因为数据库守护进程已经打开了数据文件,并通过内存(也许是磁盘)中的结构来处理动态锁定.一旦服务器启动并运行,就不知道如何在任何特定的服务器数据库中实现它.

The advice for opening and closing connections is based around an assumption of a database server being on the other end of the connection. If you consider how that works, the cost of opening and closing the connection is very slight, as the database deamon has the data files already open, and handles locking on the fly via structures in memory (and perhaps on disk -- I really don't know about how it's implemented in any particular server database) that already exist once the server is up and running.

使用Jet/ACE,所有用户都在争用两个文件,即数据文件和锁定文件,设置该文件的成本比创建到服务器数据库的新连接的增量成本要昂贵得多.

With Jet/ACE, all users are contending for two files, the data file and the locking file, and setting that up is much more expensive than the incremental cost of creating a new connection to a server database.

现在,在您希望通过Jet/ACE数据存储实现高并发的情况下,可能必须在这些因素之间进行权衡,并且通过更痛苦地处理连接可能会获得更高的并发性. .但是我要说的是,如果您进入Jet/ACE领域,您可能应该首先考虑升级到基于服务器的后端,而不是浪费时间针对环境优化Jet/ACE,这不是设计.

Now, in situations where you're aiming for high concurrency with a Jet/ACE data store, there might have to be a trade-off among these factors, and you might get higher concurrency by being much more miserly with your connections. But I would say that if you're into that realm with Jet/ACE, you should probably be contemplating upsizing to a server-based back end in the first place, rather than wasting time on optimizing Jet/ACE for an environment it was not designed for.

这篇关于最好在每次操作之后都将其关闭以更好地关闭Access DB,以便以后进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆