python sqlserver api连接池_驱动程序感知连接池 - SQL Server | Microsoft Docs

本文介绍了Python连接SQL Server时使用API连接池的方法,特别是关于驱动程序感知连接池的概念,它允许驱动程序自定义ODBC连接池行为,以解决连接池碎片和应用程序首选项的问题。驱动程序感知连接池可以通过设置SQL_ATTR_CONNECTION_POOLING属性为SQL_CP_DRIVER_AWARE来启用,但需要注意的是,游标库不支持此功能。
摘要由CSDN通过智能技术生成

识别驱动程序的连接池Driver-Aware Connection Pooling

01/19/2017

本文内容

驱动程序感知连接池是 Windows 8 中的驱动程序管理器的一项新功能。Driver aware connection pooling is a new feature of the Driver Manager in Windows 8. 驱动程序感知连接池允许驱动程序编写器自定义 ODBC 驱动程序中的连接池行为。Driver aware connection pooling allows driver writers to customize the connection pooling behavior in their ODBC driver.

备注

游标库不支持驱动程序感知连接池。Driver aware connection pooling is not supported with cursor library. 当启用了驱动程序感知连接池时,如果应用程序尝试通过 SQLSetConnectAttr 启用游标库,则该应用程序将收到错误消息。An application will receive error message if it attempts to enable cursor library via SQLSetConnectAttr, when driver aware connection pooling is enabled.

驱动程序感知连接池解决了与驱动程序管理器连接池相关的下列问题:Driver aware connection pooling addresses the following problems related to Driver Manager connection pooling:

池碎片 如果与新的连接请求的连接字符串完全匹配,则驱动程序管理器将仅从池中返回连接。Pool Fragmentation The Driver Manager will only return a connection from the pool if it is an exact match with the connection string of a new connection request. 驱动程序管理器需要完全匹配的一个原因是,驱动程序管理器不了解每个特定于驱动程序的连接字符串关键字及其值。One reason for the Driver Manager to require an exact match is that the Driver Manager does not understand every driver-specific connection string keyword and its value. 但是,某些连接字符串关键字值 ((例如数据库) 的名称)可能不需要完全匹配,因为驱动程序可以更改数据库的时间不会超过打开新连接所需的时间, (准确的时间差异取决于数据源) 。However, some connection string keyword values (such as the name of the database) may not require an exact match, since the driver can change the database in less than the time needed to open a new connection (the exact time difference depends on the data source). 而且,某些连接属性中的差异 (例如 SQL_ATTR_CURRENT_CATALOG) 可能需要更多的时间来更改其他 (属性中的差异,如 SQL_ATTR_LOGIN_TIMEOUT) 。And, differences in some connection attributes (such as SQL_ATTR_CURRENT_CATALOG) can take more time to change than differences in other attributes (such as SQL_ATTR_LOGIN_TIMEOUT). 这也会阻止驱动程序管理器使用从池中的最小成本、可重复使用的连接。This, too, can prevent the Driver Manager from using the lowest-cost, reusable connection from the pool. 当驱动程序必须创建多个新连接时,应用程序的性能可能会降低,并且数据源的可伸缩性可能会降低。When a driver has to create many new connections, an application's performance can decrease and the data source scalability can decrease. 池碎片可以通过驱动程序感知连接池降低,因为驱动程序可以更好地估计在池中为连接请求重复使用连接的成本。Pool fragmentation can be reduced with driver-aware connection pooling because a driver can better estimate the cost of reusing a connection in the pool for a connection request.

不考虑应用程序首选项 与重置) 的某些属性相比,某些数据源可以有效地 (打开新连接,因此,应用程序可能更倾向于打开新连接,而不是尝试重新使用来自池的稍微不匹配的连接并重置某些值 (但这可能会在连接池初始化短语) 期间慢一些。No consideration of application preference Some data sources can efficiently open new connections (compared to resetting some attributes), so, an application may prefer to open a new connection instead of trying to reuse a slightly mismatched connection from the pool and reset some values (although this may be slower during the connection pool initialization phrase). 但是,某些应用程序可能会使服务器负载更小并打开更少的连接,不过,为正确的行为修复不匹配的开销可能会更大。But some applications may keep the server load smaller and open fewer connections, although there may be a bigger cost to fix the mismatches for correct behavior. 如果没有驱动程序感知连接池,则由于驱动程序管理器无法识别所有特定于驱动程序的连接属性,因此不能有效地指定此类首选项。Without driver-aware connection pooling, you cannot specify this kind of preference effectively, because the Driver Manager does not recognize all driver-specific connection attributes. 驱动程序感知连接池允许驱动程序使用 SQLSetConnectAttr) 的特定于驱动程序的属性获取用户首选项 (,以便它能够更好地估算基于用户首选项从池中重复使用连接的成本。Driver-aware connection pooling allows a driver to obtain the user preference (with a driver-specific attribute of SQLSetConnectAttr) so that it can better estimate the cost of reusing a connection from the pool based on a user's preference.

有关驱动程序感知连接池的详细信息,请参阅 在 ODBC 驱动程序中开发连接池感知。For more information about driver-aware connection pooling, see Developing Connection-Pool Awareness in an ODBC Driver.

确定驱动程序支持Determining Driver Support

驱动程序感知连接池是驱动程序可能不支持的一项可选功能。Driver-aware connection pooling is an optional feature that a driver may not support. 若要确定驱动程序是否支持该驱动程序,请使用 SQL_DRIVER_AWARE_POOLING_SUPPORTED InfoType of SQLGetInfo。To determine if a driver supports it, use the SQL_DRIVER_AWARE_POOLING_SUPPORTED InfoType of SQLGetInfo.

如何启用可识别驱动程序的连接池How to Enable Driver-Aware Connection Pooling

应用程序可以通过将 SQL_ATTR_CONNECTION_POOLING 特性设置为与 SQLSetEnvAttrSQL_CP_DRIVER_AWARE 来使用驱动程序的连接池感知。An application can use a driver's connection-pooling awareness by setting the SQL_ATTR_CONNECTION_POOLING attribute to SQL_CP_DRIVER_AWARE with SQLSetEnvAttr. 如果驱动程序不支持连接池感知,则使用的驱动程序管理器连接池 (与 SQL_CP_ONE_PER_HENV 指定的相同,而不是 SQL_CP_DRIVER_AWARE) 。If a driver does not support connection-pool awareness, Driver Manager connection pooling will be used (same as if SQL_CP_ONE_PER_HENV had been specified, instead of SQL_CP_DRIVER_AWARE). ODBC 2.x 和1.x 应用程序可以启用此功能。ODBC 2.x and 3.x applications can enable this feature.

另请参阅See Also

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值