连接对象重用 [英] Connection Object reuse

查看:53
本文介绍了连接对象重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我指的是使用在类级别(私有)声明的new(vb)新关键字创建的连接。它以各种方法打开和关闭。我没有遇到过问题但很有经验的人说这很糟糕。阅读文档,似乎
连接一旦调用Close(),连接就会返回到池中。如果无法进行常规回复,则可以限制SQL Server提供程序。我想知道它为什么不好。



Mary

I refer to a connection created with the new (New in vb) keyword declared at the class level (private). It is opened and closed in various methods. I have not had problems but very experienced people have said this is very bad. Reading the docs, it seems the connection that once Close() is called the connection is returned to the pool. If a general reply is not possible, limiting to SQL Server provider is fine. I would like to know why it is bad.


Mary

推荐答案

您在Visual Basic .NET论坛中提出了这个问题我确实提供了答案:

You asked this question in the Visual Basic .NET forum and I did provide an answer:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/fdc1d30f-5c88-4f08-a9c8- 939d2b34adfc / whats-wrong-with-reusing-a-connection-object?forum = vbgeneral

使用基于文件的数据库(如Microsoft Access)确实增加了损坏的风险维护持久连接,尤其是在网络环境中。对于服务器类型数据库,您只需维护一个未使用的资源(连接到服务器管理的数据库
)。如果有许多用户,则持久连接可能会影响数据库性能。经验丰富的DBA监控数据库服务器可能会想知道为什么所有这些连接
都会持续很长一段时间。

With file based databases such as Microsoft Access you do increase the risk of corruption by maintaining persistent connections, especially in a network environment. With respect to server type databases you're simply maintaining a resource (connection to the database that is managed by the server) that is not being used. If there are many users, persistent connections can impact database performance. An experienced DBA monitoring the database server will probably wonder why all of these connections are persisting over extended periods of time.

这就是为什么建议只根据需要请求连接,然后在完成或不需要时关闭。

This is why it is recommend that connections only be requested as needed and then closed when finished or not needed.


这篇关于连接对象重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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