#12003/12/2 14:39:55
一直以来,我调用数据库的方法都是延用了王国荣《ASP网页制作教程中》的方法:
<!--#include virtual="/func/db.fun-->
<%
sql="select * from [数据表]"
set rs=GetMdbRecordSet("test.mdb",sql)
%>
其中,db.fun内容如下:
<%
'---------------------------------------------------
Function GetMdbConnection( FileName )
Dim Provider, DBPath
Provider = "Provider=Microsoft.Jet.OLEDB.4.0;"
DBPath = "Data Source=" & Server.MapPath(FileName)
Set GetMdbConnection = GetConnection( Provider & DBPath )
End Function
'---------------------------------------------------
Function GetMdbRecordset( FileName, Source )
Set GetMdbRecordset = GetMdbRs( FileName, Source, 2, "" )
End Function
'---------------------------------------------------
Function GetConnection( Param )
Dim conn
On Error Resume Next
Set GetConnection = Nothing
Set conn = Server.CreateObject("ADODB.Connection")
If Err.Number <> 0 Then Exit Function
conn.Open Param
If Err.Number <> 0 Then Exit Function
Set GetConnection = conn
End Function
'---------------------------------------------------
Function GetMdbRs( FileName, Source, Cursor, Password )
Dim conn, rs
On Error Resume Next
Set GetMdbRs = Nothing
If Len(Password) = 0 Then
Set conn = GetMdbConnection( FileName )
Else
Set conn = GetSecuredMdbConnection( FileName, Password )
End If
If conn Is Nothing Then Exit Function
Set rs = Server.CreateObject("ADODB.Recordset")
If Err.Number <> 0 Then Exit Function
rs.Open source, conn, Cursor, 2
If Err.Number <> 0 Then Exit Function
Set GetMdbRs = rs
End Function
%>
我也一直觉得很方便,可是今天当我的网站在线人数超过300人的时候,网站却打不开了,出现了脚本超时错误。
请问王国荣的这种调用方法效率是最高的吗,怎样才能提高ASP调用MDB数据库的性能?