简体   繁体   English

.NET ODBC连接池

[英].NET ODBC Connection Pooling

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. 编辑:我需要从程序中获取此信息,我不能在部署程序的每台PC上手动检查它。

MSDN as in-depth guidelines on this MSDN作为对此的深入指导

Configuring Connection Pooling from the Data Source Administrator 从数据源管理员配置连接池

[snip] [剪断]

Alternatively, you can start the ODBC Data Source Administrator at the Run prompt. 或者,您可以在“运行”提示符下启动ODBC数据源管理器。 On the taskbar, click Start, click Run, and then type Odbcad32. 在任务栏上, 单击“开始”,单击“运行”,然后键入Odbcad32。

The tab for managing connection pooling is found in the ODBC Data Source Administrator dialog box in version ODBC 3.5 and later. 用于管理连接池的选项卡位于ODBC 3.5及更高版本的“ODBC数据源管理器”对话框中。 Configuring Connection Pooling from the Registry 从注册表配置连接池

For versions prior to version 3.5 of the ODBC core components, you need to modify the registry directly to control the connection pooling CPTimeout value. 对于ODBC核心组件版本3.5之前的版本,您需要直接修改注册表以控制连接池CPTimeout值。

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). 重点是在.NET中你不必担心它(例如,这就是你在使用SQL Server时应该总是使用SqlConnection的原因 - 部分原因是它启用了连接池)。

Update 更新

On Vista, just type "ODBC" in the Start menu and it will find the app for you. 在Vista上,只需在“开始”菜单中键入“ODBC”,它就会找到适合您的应用程序。

Update Following Clarification from OP 从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). 在确定是否在每台计算机上启用了连接池方面,查看MSDN指南,如果您检查注册表值,我会说您最好(请参阅本文以获取有关注册表访问的指示)。

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. TBH虽然,除非客户端机器真的很糟糕,我甚至可能都不会打扰.. AFAIK它默认启用,并且在客户端机器上打开连接(根据我的经验)从来没有什么大不了的。 It only really becomes a big deal when lots are being opened. 批量打开时,它才真正成为一件大事。

Looks like you can just read this registry key: 看起来你可以只读这个注册表项:

[HKEYLOCALMACHINE]\\SOFTWARE\\ODBC\\ODBCINST.INI\\SQL Server\\CPTimeout [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. 如果值为0,则禁用连接池。 If it's any value above 0, it's enabled. 如果它是0以上的任何值,则启用它。

See: 看到:

http://msdn.microsoft.com/en-us/library/ms810829.aspx 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? 只是好奇:为什么你需要知道这个数字?

To determine the number of open connections on each db, try this sql - I got it from a document on internet 要确定每个数据库上的打开连接数,请尝试使用此sql - 我是从Internet上的文档中获取的

select  db_name(dbid) , count(*) 'connections count'
  from master..sysprocesses
 where spid > 50 and spid  @@spid
 group by  db_name(dbid)
 order by count(*) desc

Spids <=50 are used by sqlserver. spid <= 50由sqlserver使用。 So the above sql would tell you the connection used by your programs. 所以上面的sql会告诉你程序使用的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM