OLEDB Resource(Session) Pooling (在Ado开发中使用连接池)

ado|session

 
Oracle: OLEDB Resource(Session) Pooling
by Eric Ma EMa@ompus.jnj.com

Database connectivity is a prerequisite for today's dynamically generated web pages. However, connection to databases is one of the most expensive operations one does from within an ASP page, because of the overhead involved in database user authentication and allocation of database resources to handle user interaction with the database, among other things. All these can add significant latency to your web site. Based on the recent discussions in this list, it is apparent that everyone is keenly aware of this issue and would like to minimize the negative impact on performance by having to connect to databases. For a programmer with a client/server programming background, it is natural for the person to design a solution based on using a database connection that persists through an entire user session. However, for a web-based application, this is a big no-no (see the article at /advice/dbsessionapp.asp  for reasons why you should never do this).

The best practice for database connection (we limit our discussion to Oracle here) from an ASP application is to open the connection at late as you can, and close it as soon as you can, which means you open and close database connection on every ASP page. The encouraged practice is to use just one set of Oracle username/password for your entire application, not one set for each user as you may be used to do with client/server applications. Access control is no longer performed by the database, but by your application. You can save the ADO connection string in an application variable in the global.asa file. Some other alternatives include saving it in the windows Registry, or use an include file that has the ADO connection information, and include that file in the pages where database connection is required.

Opening a new database connection for each ASP page may not be as bad as you think, because from ADO 2.0 up you can utilize the "resource (session) pooling" feature offered by Microsoft's OLE DB Provider for Oracle. Resource pooling is similar to ODBC connection pooling, where a connection is returned to a pool instead of being destroyed immediately after it is closed and set to nothing in your code. See the following article for more details:
http://msdn.microsoft.com/library/techart/pooling2.htm.

The purpose of this FAQ is to demonstrate how to properly set the environment on your IIS/NT server to take advantage of OLE DB resource pooling. Unlike with ODBC, where you can enable pooling and set the timeout parameter from the 32-Bit ODBC utility in the Control Panel, with OLE DB you have to directly work on the Registry itself. Again, this is not as scary as it sounds. To do so, you first determine the version of OLE DB Provider you are using by running the script found at: http://www.learnasp.com/learn/connectioninfo.asp, then dependent on the version you have, you may do the following steps:

?If you are using the OLE DB 2.0 provider you can do resource pooling but you cannot modify the default timeout configuration (60 seconds). To set up resource pooling, add the following subkey in the Registry:
HKEY_CLASSES_ROOT\CLSID\{e8cc4cbe-fdff-11d0-b865-00a0c9081c1d}\OLEDB_Services. Make sure you use the DWORD type, and enter a hexadecimal value of 0xffffffff.

However, I suggest that you don't use the 2.0 version of the Provider any more because of potential memory leaks. See the following KB article for more:
http://support.microsoft.com/support/kb/articles/q194/3/87.asp

?If you use the OLE DB 2.1 or 2.5 provider, in addition to doing the above step, you can configure the pooling timeout parameter by adding the following subkey:
HKEY_CLASSES_ROOT\CLSID\{e8cc4cbe-fdff-11d0-b865-00a0c9081c1d}\SPTimeout. Again this entry is of a DWORD type and you enter a decimal value in seconds. It is up to you to decide the number of second you want to set, depending on how busy your site is and how frequent the pages need to access Oracle data.

A KB article describing the above step can be found at:
http://support.microsoft.com/support/kb/articles/q237/9/77.asp

After you make the above changes, reboot your NT Server to make the Registry changes take effect. This is step is necessary.

Congratulations, now you are using the wonderful feature of OLE DB resource pooling! I hope from today on you will never ever think about caching connection objects in session variables anymore! Treat it as evil!

Some side notes and observations:

?With Oracle, in order to use resource pooling, you need to add the Registry subkey. Having only "OLE DB Services = -1" in your connection string is not enough.

?I came across the following KB article in MSDN saying OLE DB resource pooling is automatica

时间: 2024-12-30 17:49:16

OLEDB Resource(Session) Pooling (在Ado开发中使用连接池)的相关文章

java web-javaweb 中的连接池出错

问题描述 javaweb 中的连接池出错 出错提示 javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 下面是我的测试的类 ```public class myCon

jsp中实现连接池

js 在JSP里有两种实现的办法,一种是用JNDI(Java Naming Directory Interface),这可能和应用服务器有关,如果是Resin,先在resin.conf里定义 <resource-ref> <res-ref-name>jdbc/oracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <init-param driver-name=&quo

spring 配置文件中dbcp连接池,jdbc连接池 引入 配置文件properties,但是不能用$符号引用里面的变量问题

spring 配置 注意红色字体 (1)懒加载要设为true,(2)引入配置文件  注意不能懒加载不能设为false,否则$不能引入配置文件中的变量 第一种配置 jdbc连接池 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3

ADO开发中如何得到表格字段名

在数据库的开发过程中,常用的操作不仅有添加.修改.删除记录,还有对字段的操作,而获得字段名就是其中的一种.获得字段名之前必须先与数据库建立连接,再打开相应的表,再得到表的字段集,下面以一程序为例,说明如何得到字段名. 新建一 VC MFCAppWizard(exe)工程,类型为Dialog based: 添加一按钮名为"显示字段",添加一 Listbox控件: 创建 Access数据库FTI.mdb: 运行效果如图所示: 1.代码说明 (1)在 stdafx.h 加入如下代码引入 AD

Servlet开发中JDBC的高级应用

servlet|高级 连结数据库 JDBC使用数据库URL来说明数据库驱动程序.数据库URL类似于通用的URL,但SUN 在定义时作了一点简化,其语法如下: Jdbc::[node]/[database] 其中子协议(subprotocal)定义驱动程序类型,node提供网络数据库的位置和端口号,后面跟可选的参数.例如: String url="jdbc:inetdae:myserver:1433?language=us-english&sql7=true" 表示采用inetd

.net 中的SqlConnection连接池机制详解_实用技巧

正确的理解这个连接池机制,有助于我们编写高效的数据库应用程序. 很多人认为 SqlConnection 的连接是不耗时的,理由是循环执行 SqlConnection.Open 得到的平均时间几乎为0,但每次首次open 时,耗时又往往达到几个毫秒到几秒不等,这又是为什么呢? 首先我们看一下 MSDN 上的权威文档上是怎么说的 Connecting to a database server typically consists of several time-consuming steps. A

如何解决 SQL Server 2000 中的连接问题

server|解决|问题 如何解决 SQL Server 2000 中的连接问题适用于 重要说明:本文包含有关修改注册表的信息.修改注册表之前,一定要备份注册表,并且一定要知道在发生问题时如何还原注册表.有关如何备份.还原和编辑注册表的信息,请单击下面的文章编号,以查看 Microsoft 知识库中相应的文章: 256986 Microsoft Windows 注册表说明 本任务的内容概要 解决连接问题 验证 DNS 设置 验证启用的协议和别名 验证 SQL Server 实例正在正确地侦听 解

ADO.NET之连接池技术的使用详解_实用技巧

连接到数据库服务器通常需要一定的时间,且服务器也需要一定的资源来处理连接.Web应用程序有时处理成千上万的连接,需要相当多的资源来处理连接.ADO.NET具有连接池的特性,连接池的功能是保留一定数量的连接,当用户使用相同的连接字符串再次连接服务器时,ASO.NET将使用连接池中的连接而不用重新发起一次连接过程.当调用Close方法关闭连接时,ADO.NET将使用连接池中的连接而不用重新发起一次连接过程.当调用Close方法关闭连接时,连接将会返回到连接池中,下次再次调用Open方法时,将从连接池

php开发中session使用

在PHP开发中对比起Cookie,session是存储在服务器端的会话,相对安全,并且不像Cookie那样有存储长度限制,本文简单介绍session的使用. 由于Session是以文本文件形式存储在服务器端的,所以不怕客户端修改 Session 内容.实际上在服务器端的Session文件,PHP自动修改session文件的权限,只保留了系统读和写权限,而且不能通过ftp修改,所以安全得多. 对于 Cookie 来说,假设我们要验证用户是否登陆,就必须在 Cookie 中保存用户名和密码(可能是