Therefore, to save server resources, you should close the connection whenever possible to release the resources occupied by the connection. This technology that closes the connection of the record set without closing the record set is called the disconnection record set, this record set is called a disconnected record set.
Next we will use an example to describe how to use this technology (NorthWind. mdb is a database that comes with Microsoft Access97, and the file adovbs. inc can be found under C: \ Program Files \ Common Files \ System \ ADO ):Copy codeThe Code is 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 forwarder ID, company name, phone number FROM forwarder"
ObjRS. Open strQ, Cnn, ad1_text
Set objRS. ActiveConnection = Nothing 'disconnects the record Set.
Cnn. Close 'Close the connection
Set Cnn = Nothing
Response. Write "<HTML> <BODY>"
'Use the disconnected record set below
Do While (Not objRS. EOF)
StrOut = objRS ("Freight dealer ID") & "," & objRS ("company name") & "," & objRS ("phone ")
Response. Write Server. HTMLEncode (strOut) & "<BR>"
ObjRS. MoveNext
Loop
Response. Write "<BR> prepare to add or insert a record :"
'If you want to update the database, you need to reestablish 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 ("phone") = "571-7227298"
ObjRS. Update
Response. Write "if the record that meets this condition does not exist, Add. <BR>"
Else
ObjRS ("phone") = "571-7227071"
Response. Write "if the record meets this condition exists, Update. <BR>"
ObjRS. Update
End If
Set objRS. ActiveConnection = Nothing
Cnn. close
Set Cnn = Nothing
ObjRS. Close
Set objRS = Nothing
Response. Write "</BODY> </HTML>"
%>