Example of a disconnected database connection

Source: Internet
Author: User
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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.