单用户数据库连接最佳实践

发布于 2024-10-08 23:00:40 字数 372 浏览 0 评论 0原文

对于 MS Access 单用户,

自始至终保持持久连接是好习惯还是可以?

伪代码:

app.start();
access.connect();
domanymanystuff();
access.disconnect();
app.exit();

--- 或 ----

app.start();
access.connect();
doonetask();
access.disconnect();
...
access.connect();
doanothertask();
access.disconnect();
...
app.exit();

With MS Access single user,

Is it good practice or okay to maintain a persistent connection throughout?

psuedocode:

app.start();
access.connect();
domanymanystuff();
access.disconnect();
app.exit();

--- OR ----

app.start();
access.connect();
doonetask();
access.disconnect();
...
access.connect();
doanothertask();
access.disconnect();
...
app.exit();

?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哭了丶谁疼 2024-10-15 23:00:40

老实说,这并不重要,因为大多数数据连接都是池化的,并且在关闭它们后会保留以供重用。您确实希望确保您的事务以“每个工作单元”的方式执行。

否则,即使使用单个用户数据库,您也可能会发现应用程序将自身锁定。

所以,试试这个:

Open connection
Start transaction
Perform unit of work
Commit transaction
...    
Start transaction
Perform unit of work
Commit transaction
...    
Start transaction
Perform unit of work
Commit transaction
...
Close connection

Honestly it won't matter since most data connection are pooled and will hang around for reuse after you have closed them. You do want to make sure that your transactions are performed in a 'per unit of work' fashion.

Otherwise, even with a single user DB you could find your application locking itself out.

So, try this:

Open connection
Start transaction
Perform unit of work
Commit transaction
...    
Start transaction
Perform unit of work
Commit transaction
...    
Start transaction
Perform unit of work
Commit transaction
...
Close connection
谈场末日恋爱 2024-10-15 23:00:40

您可以在整个过程中与单用户数据库保持持久连接。

You can maintain a persistent connection throughout with a single-user database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文