Disconnect | data | database | Database connection A key condition for using a disconnected recordset is to use the client temp table, which is
Specify rs.cursorlocation = adUseClient or 3, below is a complete
Examples of:
Demo-1.asp (Online Demo: http://www.aspcn.com/demo/demo-1.asp)
------------------------------------------------------------
<%@ Language=vbscript%>
<%
'# -------------------------------------------------------------------
---------
' # Program Description: Demo use broken recordset
' # program Design: Jahau
'# -------------------------------------------------------------------
---------
On Error Resume Next
Dim adoconn,adors,sqlcmd,connectstring
'#--------------------------------------------------------------------
---------
' # Connect to the database using SQL Server's Dsn-less method
'#--------------------------------------------------------------------
---------
ConnectString = "Driver={sql Server};" & _
"Server= (local);" & _
"DATABASE=ABC;" & _
"UID=SA;" & _
"Pwd=123"
'#--------------------------------------------------------------------
---------
' # Create an object instance and initialize the connection (Connection)
'#--------------------------------------------------------------------
---------
Set adoconn = Server.CreateObject ("ADODB. Connection ")
Set adors = Server.CreateObject ("ADODB. Recordset ")
Adoconn.open connectstring
SQLCMD = "SELECT * from Bbs_user where LTrim (RTrim (id)) = ' w3org '"
'#--------------------------------------------------------------------
---------
' # Use the client temporary table to open and save the Recordset, the key!
' # The client is the host running the ASP program, relative to the database server
'#--------------------------------------------------------------------
---------
adors.cursorlocation = 3 ' Const adUseClient = 3
Adors.open sqlcmd,adoconn,0,2
'#--------------------------------------------------------------------
---------
' # no record found, end program
'#--------------------------------------------------------------------
---------
Err.Clear
If adors.eof and Adors.bof Then
Adors.close
Adoconn.close
Set adors = Nothing
Set adoconn = Nothing
Response.Write "The user did not find out! "
Response.End
End If
'#--------------------------------------------------------------------
---------
' # Find the record, display the original value, release the recordset's active connection, and then close the database connection
'#--------------------------------------------------------------------
---------
Response.Write "The original nickname is:" & Trim (Adors.fields ("nickname"). Value)
& "<br>" & VbCrLf
Set adors.activeconnection = Nothing ' frees the active connection of RS
Adoconn.close
Response.Write "The connection is closed! <br> "& VbCrLf
'#--------------------------------------------------------------------
---------
' # Assign a new value to the record's nickname column, when there is no active database connection
'#--------------------------------------------------------------------
---------
Adors.fields ("nickname"). Value = "newtest-" & Second (Time ())
'#--------------------------------------------------------------------
---------
' # Open the database connection again, and bind to the previous recordset
'#--------------------------------------------------------------------
---------
Adoconn.open connectstring
Adors.activeconnection = Adoconn
'#--------------------------------------------------------------------
---------
' # Update the recordset and display the new value
'#--------------------------------------------------------------------
---------
Adors.update
Response.Write "The new nickname is:" & Trim (Adors.fields ("nickname"). Value) &
"<br>" & VbCrLf ' shows a result
'#--------------------------------------------------------------------
---------
' # If an error occurs, an error is displayed
'#--------------------------------------------------------------------
---------
If err.number <> 0 Then
Response.Write "Error occurred:" & Err.Description & "<br>"
End If
Adors.close
Adoconn.close
Set adors = Nothing
Set adoconn = Nothing
%>
<HTML>