让 Win Form 本地数据库连接保持打开状态?

发布于 2024-08-18 09:00:08 字数 160 浏览 3 评论 0原文

首先,我理解为什么尽快关闭服务器数据库连接是一个好习惯。

我正在开发一个程序,其中包含一个本地数据库(5 个表〜200 列),它可能会增长到几千行(所以怀疑这会带来太大的开销)。我的第一个想法是保持本地数据库连接直到程序关闭。

您能否确认这是否可以或强调我不想这样做的原因?

First up, I understand why it is good practice to close server database connections as soon as possible.

I am developing a program that will contain a local database (5 tables ~ 200 columns), it may grow to a few thousand rows (so doubt it will be too much of an overhead). My first thought was to keep the local db connection until the program is closed.

Can you please confirm if this will be ok or highlight reasons why I would not want to do this?

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

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

发布评论

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

评论(3

浊酒尽余欢 2024-08-25 09:00:08

默认情况下,ADO.NET 与大多数数据库引擎一起在后台提供自动连接池。绝对没有必要保持连接打开,因为 ADO.NET 无论如何都会为您做这件事,并在您重新打开它时将其返还。只要关闭它,就少了一件需要担心的事情。

ADO.NET in conjunction with most database engines provide automatic connection pooling in the background by default. There's absolutely no need to keep the connection open as ADO.NET will do that for you anyway and give it back when you reopen it. Just close it, one less thing to worry about.

情徒 2024-08-25 09:00:08

您想要保持连接打开有什么特殊原因吗?您想通过这样做实现什么目标?

如果它是一个单用户应用程序,数据库将为该程序的一个实例提供服务,理论上我想这不会有什么坏处。但是,如果您的应用程序变成由多个人使用的应用程序,针对同一数据库运行,则可能会成为一个问题。

我会说;坚持推荐的做法,除非您有非常的理由不这样做。

Is there any particular reason why you want to keep the connection open? What is it that you want to achieve by doing that?

If it is a single user application, where the database will serve one single instance of the program, theoretically I guess it would not hurt. However, if your application should turn into an application that is used by several people running against the same database, it may become an issue.

I would say; stick to recommended practice, unless you have really good reasons not to.

一抹淡然 2024-08-25 09:00:08

@弗雷德里克
是的,这将是到其用户配置文件上的 localDB 的单个用户连接。我认为保持打开状态的唯一原因是避免重新连接时可能出现的异常,但我认为连接池响应总结了它,所以我很乐意继续并在完成后关闭。

@DrJokepu
干杯

@Fredrik
Yes it would be a single user connection to a localDB on their user profile. Only reason I thought of keeping it open would be to avoid possible Exceptions when re-connecting but I think the connection pooling response sums it up so I am happy to go ahead and close when finished.

@DrJokepu
Cheers

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