把記錄集從數據庫取出之後,就把數據庫關掉,即使是壹批數據也是如此,對數據庫的讀取操作只有壹次,但可能已經讀取出上千上萬條數據了。讀取完成後,數據庫本身就是靜止狀態了。
---------------------------------------------
Function GetRecordset(SQLString)
Dim MM_Recordset_cmd
Set MM_Recordset_cmd = Server.CreateObject ("ADODB.Command")
MM_Recordset_cmd.ActiveConnection = MM_Conn_STRING
MM_Recordset_cmd.CommandText = SQLString
MM_Recordset_cmd.Prepared = true
Set GetRecordset = MM_Recordset_cmd.Execute
End Function
Sub ReleaseRecordset(MM_Recordset)
MM_Recordset.Close
Set MM_Recordset = Nothing
End Sub
Sub RDBConn()
Set MM_Recordset = Nothing
Conn.Close
Set Conn = Nothing
End Sub
----------------------------------------------------
以下是調用方法示例:
-----------------------------------------------------
Sub InfoList_Style(InfoSorts,MaxRow)
SQLString = "select * from table_infomation where Info_CateID like '%" & InfoSorts & "%' order by Info_createdate desc"
set MM_Recordset = GetRecordset(SQLString)
Row = 1
Do While Not MM_Recordset.Eof
BGC = "#FFFFFF"
Row = Row + 1
IF Row Mod 2 = 0 Then BGC = "#EFEFEF"
infodate=year(MM_Recordset.Fields.Item("info_createdate").Value)&"/"&month(MM_Recordset.Fields.Item("info_createdate").Value)&"/"&day(MM_Recordset.Fields.Item("info_createdate").Value)
%>
<li style="width:260px; background-color:<%=BGC%>; height:20px; padding-top:5px;">
<div class="info_title" style="width:190px;"><a href="news.asp?id=<%=MM_Recordset.Fields.Item("info_id")%>" title="<%=MM_Recordset.Fields.Item("info_title")%>"><%=LeftStr(MM_Recordset("info_title"),14,14)%></a></div>
<div class="info_date"><%=infodate%></div>
<div class="clear"></div>
</li>
<%
IF Row > MaxRow Then Exit Do
MM_Recordset.movenext
Loop
ReleaseRecordset(MM_Recordset)
End Sub
--------------------------------------------------------------
這個網站的首頁就是用這種方式打開數據庫的,並沒有任何不良反應,雖然它用的是AC數據庫,但從數據庫讀取這點上比妳的方法要好很多。