1、在global.asa中创建连接池
<script language=VBScript RUNAT="Server"> 'You can add special event handlers in this file that will get run automatically when 'special Active Server Pages events occur. To create these handlers, just create a 'subroutine with a name from the list below that corresponds to the event you want to 'use. For example, to create an event handler for Session_OnStart, you would put the 'following code into this file (without the comments): 'Sub Session_OnStart '**Put your code here ** 'End Sub 'EventName Description 'Session_OnStart Runs the first time a user runs any page in your application 'Session_OnEnd Runs when a user's session times out or quits your application 'Application_OnStart Runs once when the first page of your application is run for the first time by any user 'Application_OnEnd Runs once when the web server shuts down Sub Application_OnStart 'Get an instance of the Connection Pooling object and create a pool of OraDatabase OraConnection.CreateDatabasePool 1,40,200,"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.8.6.205)(PORT=1521))(CONNECT_DATA=(SID=WYX)))", "bii/12345", 0 '| | |_ timeout seconds '| |_ max size '|_ init size End Sub Sub Session_OnStart Session.Timeout=60 Server.ScriptTimeout=999999 set Session("OraDataBase")=OraConnection.GetDatabaseFromPool(10) '|_ wait time seconds MPSInit() End Sub Sub Session_OnEnd set Session("OraDataBase")=nothing End Sub Sub Application_OnEnd OraConnection.DestroyDatabasePool End Sub
</script> <OBJECT RUNAT=Server SCOPE=Application ID=OraConnection PROGID="OracleInProcServer.XOraSession"></OBJECT>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
'Get an instance of the Connection Pooling object and create a pool of OraDatabase OraConnection.CreateDatabasePool 1,40,200,"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.8.6.205)(PORT=1521))(CONNECT_DATA=(SID=WYX)))", "bii/12345", 0 '
'1-----init pool size
'40---max pool size
'200-timeout seconds
End Sub
Sub Session_OnStart
Session.Timeout=60
Server.ScriptTimeout=999999
set Session("OraDataBase")=OraConnection.GetDatabaseFromPool(10) '
'10----wait time seconds
End Sub
Sub Session_OnEnd
Session("OraDataBase").Close
set Session("OraDataBase")=nothing
End Sub
Sub Application_OnEnd
OraConnection.DestroyDatabasePool
End Sub
</SCRIPT>
2、在其它页面中进行引用
dim OraDynaset,sql
sql="select * from tablename"
set OraDynaset=Session("OraDataBase").DbCreateDynaset(sql,0)
do while not OraDynaset.Eof
……
OraDynaset.DbMoveNext
loop
事务用法:
Session("Oradatabase").BeginTrans
Session("Oradatabase").RollBack
Session("Oradatabase").CommitTrans
注:在WEB服务器上在确保安装有ORACLE客户端组件------》Oracle Object For OLE