Therefore, to conserve server resources, the connection should be shut down as much as possible to free up resources for the connection, and the technique of shutting down the recordset without closing the recordset is called a disconnected recordset, which itself is called a disconnected recordset.
Here's an example of how this technique is used (Northwind.mdb is a database from Microsoft Access97, file Adovbs.inc can be C:\Program Files\Common Files\ System\ado found below):
Copy Code code as follows:
<% @LANGUAGE = VBScript%>
<!--#include file= "Adovbs.inc"-->
<%
Response.Expires = 0
Dim Cnn,objrs, Strout, STRQ, STRC
strc= "Driver={microsoft Access Driver (*.mdb)}; Dbq= "& Server.MapPath (" \ASP24 ") &" \northwind.mdb; "
' Establish a connection
Set Cnn = Server.CreateObject ("ADODB.") Connection ")
Cnn.open STRC
' Create a Recordset object
Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.cursorlocation =aduseclient
Objrs.cursortype = adOpenStatic
Objrs.locktype = adLockOptimistic
STRQ = "Select Shippers ID, company name, telephone from shippers"
Objrs.open STRQ, Cnn,,, adCmdText
Set objrs.activeconnection = Nothing ' Disconnect recordset
Cnn.close ' Close connection
Set Cnn = Nothing
Response.Write "<HTML><BODY>"
' Use a broken recordset below
Do as (not objrs.eof)
Strout = objRS ("Freight forwarder ID") & "," & objRS ("Company name") & "," & objRS ("Phone")
Response.Write Server.HTMLEncode (Strout) & "<BR>"
Objrs.movenext
Loop
Response.Write <BR> Prepare new or inserted records: "
' If you need to update the database, re-establish the connection
Set Cnn = Server.CreateObject ("ADODB.") Connection ")
Cnn.open STRC
Set objrs.activeconnection = Cnn
Objrs.filter = "Company name = ' Wu Feng '"
If objrs.eof Then
Objrs.addnew
objRS ("company name") = "Wu Feng"
objRS ("telephone") = "571-7227298"
Objrs.update
Response.Write "records that qualify for this condition do not exist, add .<br>"
Else
objRS ("telephone") = "571-7227071"
Response.Write "The record that matches this condition exists, then update.<br>"
Objrs.update
End If
Set objrs.activeconnection = Nothing
Cnn.close
Set Cnn = Nothing
Objrs.close
Set objRS = Nothing
Response.Write "</BODY></HTML>"
%>