.NET ODBC 连接池
我像这样打开一个连接:
Using conn as New OdbcConnection(connectionString)
conn.Open()
//do stuff
End Using
如果启用了连接池,则该连接不会物理关闭,而是释放到池中并将被重用。 如果它被禁用,它将被物理关闭。
有什么方法可以以编程方式知道是否连接池已启用? 以及池中当前打开的已使用和未使用连接的数量?
编辑:我需要从程序内部获取此信息,我无法在将部署该程序的每台 PC 上手动检查它。
I open a connection like this:
Using conn as New OdbcConnection(connectionString)
conn.Open()
//do stuff
End Using
If connection pooling is enabled, the connection is not physically closed but released to the pool and will get reused. If it is disabled, it will be physically closed.
Is there any way of knowing programmatically if connection pooling is enabled or not? and the number of used and unused connections currently open in the pool?
EDIT: I need to get this information from within the program, I can't go and check it manually on every single PC where the program will be deployed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MSDN 对此的深入指南
池化始终由数据服务器软件处理。 重点是,在 .NET 中您不必担心它(例如,这就是为什么在使用 SQL Server 时应始终使用 SqlConnection - 部分原因是它启用了连接池)。
更新
在 Vista 上,只需在“开始”菜单中键入“ODBC”,它就会为您找到该应用程序。
OP 澄清后的更新
在确定是否在每台计算机上启用连接池方面,请查看 MSDN 指南 我想说你最好检查一下注册表值(参见
不过,除非客户端机器真的很糟糕,否则我可能根本不会打扰。据我所知,它是默认启用的,并且在客户端计算机上打开连接(根据我的经验)从来都不是一件大事。 只有当很多被打开时,它才真正成为一个大问题。
MSDN as in-depth guidelines on this
Pooling is always handled by data server software. The whole point being is that in .NET you shouldn't have to worry about it (for example, this is why you should always use the SqlConnection when working with SQL Server - part of it is that it enables the connection pooling).
Update
On Vista, just type "ODBC" in the Start menu and it will find the app for you.
Update Following Clarification from OP
In terms of determining if connection pooling is enabled on each machine, looking at the MSDN guidelines I whould say you would best best if you check the registry values (See this article for pointers on registry access).
TBH though, unless the client machines are really crappy, I would possibly not even bother.. AFAIK it is enabled by default, and opening connections on a client machine (in my experience) has never been a big deal. It only really becomes a big deal when lots are being opened.
看起来您可以读取此注册表项:
[HKEYLOCALMACHINE]\SOFTWARE\ODBC\ODBCINST.INI\SQL Server\CPTimeout
(或其某些变体,具体取决于您的操作系统和用户帐户)。 如果该值为 0,则禁用连接池。 如果它是任何大于 0 的值,则表示已启用。
请参阅:
http://msdn.microsoft.com/en-us/library/ ms810829.aspx
我不确定是否获取打开的连接数。 只是好奇:为什么你需要知道这个数字?
Looks like you can just read this registry key:
[HKEYLOCALMACHINE]\SOFTWARE\ODBC\ODBCINST.INI\SQL Server\CPTimeout
(or some variant thereof, depending on your OS and user account). If the value is 0, then connection pooling is disabled. If it's any value above 0, it's enabled.
See:
http://msdn.microsoft.com/en-us/library/ms810829.aspx
I'm not sure about getting the number of open connections. Just curious: why do you need to know the number?
要确定每个数据库上打开的连接数,请尝试此 sql - 我从互联网上的文档中获取它
Spid <= 50 由 sqlserver 使用。 所以上面的sql会告诉你程序使用的连接。
To determine the number of open connections on each db, try this sql - I got it from a document on internet
Spids <=50 are used by sqlserver. So the above sql would tell you the connection used by your programs.