保持 SQL 连接打开有什么缺点?

发布于 2024-08-19 13:22:47 字数 42 浏览 3 评论 0原文

这似乎是一个简单的问题,但我想知道不调用“close()”函数的缺点。

This seems to be a simple question, but I wonder the disadvantages of not calling the "close()" function.

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

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

发布评论

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

评论(6

白馒头 2024-08-26 13:22:47

迟早,您会遇到“已达到最大连接限制”错误。我认为这是一个主要缺点。

Sooner or later, you'll run into the "The Maximum Connection Limit Has Been Reached" error. I'd call that a major disadvantage.

〗斷ホ乔殘χμё〖 2024-08-26 13:22:47

除了耗尽连接池(到目前为止大多数答案都是如此)之外,您还面临锁定数据的危险。

如果您正在读取或写入表,某些锁定语义将导致某些行被锁定到其他连接。如果连接上有任何未完成的事务,则尤其如此。

然后,读取和写入可能会失败,并且应用程序将到处抛出异常。

简而言之,始终关闭连接。

Apart from exhausting the connection pool (as most answers so far have been), you are in danger of locking data.

If you are reading or writing to a table, some locking semantics will cause certain rows to be locked to other connections. This is especially true if you have any open transaction on the connection.

Reads and writes can then fail and the application will throw exceptions all over the place.

In short, always close the connection.

柏拉图鍀咏恒 2024-08-26 13:22:47

连接池将填满,任何新连接将超时等待池中的新连接。

The connection pool will fill up and any new connections will time out waiting for a new connection from the pool.

錯遇了你 2024-08-26 13:22:47

每个与 SQL Server 的连接都需要分配内存。

因此,打开的连接越多,正在使用和保留的内存就越多,这可能会得到更好的利用。

如果您想了解 SQL Server 中的连接使用了多少内存,请查看以下参考资料。

SQL Server 对象使用的内存

Each and every connection to SQL Server requires memory allocation.

So the more connections you have open the more memory that is being used and held, that could potentially be put to better use.

If you want to know just how much memory is used by connections in SQL Server, take a look at the following reference.

Memory Used by SQL Server Objects

陌生 2024-08-26 13:22:47

与数据库服务器的连接已打开。假设你有数百个程序访问同一服务器......

你也应该处理它

a connection to the database server is open. suppose you have 100s of programs hitting the same server...

you should also dispose it

软糯酥胸 2024-08-26 13:22:47

快速简单的答案是,越早关闭,连接池就能越早重新使用连接。

Quick simple answer is that the sooner you close, the sooner the connection can be re-used by the connection pool.

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