Recommended: Please note! Common ASP script attacks and prevention techniques Due to the convenience and ease of use of ASP, more and more website background programs use the ASP scripting language. However, because ASP itself has some security vulnerabilities, it will provide hackers with an opportunity to take advantage of it if they are not careful. In fact, security is not only a matter of network management, but programmers must also be in certain security.
When we use ASP's built-in ADO components for database programming, we usually open a connection at the beginning of the script and close it at the end of the script, but for larger scripts, the connection is open much longer in most cases than it needs to be opened. Therefore, in order to save server resources, the connection should be closed as much as possible to free up the resources occupied by the connection. This technique of closing the connection of the record set without closing the record set is called the disconnected record set, and this record set itself is called the disconnected record set.
Let's use an example to illustrate the use of this technology (NorthWind.mdb is a database that comes with Microsoft Access97, and the file adovbs.inc can be found in C:/Program Files/Common Files/System/ADO):
| The following is the quoted content: <% @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; 'Make a connection Set Cnn = Server.CreateObject(ADODB.Connection) Cnn.Open StrC 'Create Recordset object Set objRS = Server.CreateObject(ADODB.Recordset) objRS.CursorLocation =adUseClient objRS.CursorType = adOpenStatic objRS.LockType = adLockOptimistic strQ = SELECT Freighter ID, Company Name, Phone FROM Freighter objRS.Open strQ, Cnn, , adCmdText Set objRS.ActiveConnection = Nothing 'Disconnect record set Cnn.Close 'Close the connection Set Cnn = Nothing Response.Write <HTML><BODY> 'The following uses the disconnected record set Do While (Not objRS.EOF) strOut = objRS(Freighter ID) & , & objRS(Company Name) & , & objRS(Tel) Response.Write Server.HTMLEncode(strOut) & <BR> objRS.MoveNext Loop Response.Write <BR>Prepare to add or insert records: 'If you need to update the database, you need to 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(Tel) = 571-7227298 objRS.Update Response.Write If the record that meets this condition does not exist, it will be added. <BR> Else objRS(Tel) = 571-7227071 Response.Write If the record that meets 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> %> |
Share: ASP tip example: Use ASP to record the number of online users The number of visits to the Internet is a very concerning issue for every netizen who builds a website. How do you know how many people are visiting your website? How to record the number of visits every day? Here is a solution. When a user starts to access the website, the Gl on the server side