Recommended: ASP instance: Using cache to improve data display efficiency Example demonstration: First create a simple database, write a function to read it, and write a dim variable temp: The following ASP code is the referenced content: <% Function DisplayRec
| The following is the quoted content: <% Dim oConn,oRs Set oConn = Server.CreateObject(ADODB.Connection) Set ors = Server.CreateObject(ADODB.RecordSet) oConn.open Provider=Microsoft.Jet.OLEDB.4.0;Data Source= Server.MapPath(db1.mdb) Session(conn) = oConn ors.open select * from t1,Session(conn),1,1 Response.write(oRs(0)) ors.close Set ors = Nothing oConn.close Set oConn = Nothing %> |
This is the code circulating on the Internet to save the Connection object in the Seesion object. Note: Session(conn) = oConn, is this the copying of the object? Let's verify it below:
| The following is the quoted content: <% Dim oConn,oRs Set oConn = Server.CreateObject(ADODB.Connection) Set ors = Server.CreateObject(ADODB.RecordSet) oConn.open Provider=Microsoft.Jet.OLEDB.4.0;Data Source= Server.MapPath(db1.mdb) Session(conn) = oConn ors.open select * from t1,Session(conn),1,1 Response.write(Session(conn).ConnectionString) ors.close Set ors = Nothing oConn.close Set oConn = Nothing %> |
An error occurred, prompting that the object is missing: 'Session(...)'! This means that the object has not been copied successfully. So what type of Session(conn) is? We used TypeName(Session(conn)) to test it, and the result was String! Out of curiosity, let's directly output Session(conn) to see:
| The following is the quoted content: <% Dim oConn,oRs Set oConn = Server.CreateObject(ADODB.Connection) Set ors = Server.CreateObject(ADODB.RecordSet) oConn.open Provider=Microsoft.Jet.OLEDB.4.0;Data Source= Server.MapPath(db1.mdb) Session(conn) = oConn ors.open select * from t1,Session(conn),1,1 Response.write(Session(conn)) ors.close Set ors = Nothing oConn.close Set oConn = Nothing %> |
The result is:
| The following is the quoted content: Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=E:/www/db1.mdb;Mode=Share Deny None; Extended Properties=;Jet OLEDB: System database=;Jet OLEDB: Registry Path=;Jet OLEDB:Database Password=; Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False; Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False; Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False |
Isn't this the ConnectionString property value of the Connection object? The default property of the Connection object is ConnectionString. When executing Session(conn) = oConn, just assign the value of the default property of the Connection object to Session(conn). Then why can it be successful when using oRs.open select * from t1,Session(conn),1,1? Find information and find out that the second parameter of the RecordSet object open method can be a Connection object or a string of database connection information! OK, the oConn object in the above example is completely redundant, just use the following code:
| The following is the quoted content: <% Dim ors Set ors = Server.CreateObject(ADODB.RecordSet) Session(conn) = Provider=Microsoft.Jet.OLEDB.4.0;Data Source= Server.MapPath(db1.mdb) ors.open select * from t1,Session(conn),1,1 Response.write(oRs(0)) ors.close Set ors = Nothing %> |
The result is correct. OK, so far there is still one problem that has not been solved: How is the correct object copying method? Or use the Set statement:
| The following is the quoted content: <% Dim oConn,oRs Set oConn = Server.CreateObject(ADODB.Connection) Set ors = Server.CreateObject(ADODB.RecordSet) oConn.open Provider=Microsoft.Jet.OLEDB.4.0;Data Source= Server.MapPath(db1.mdb) Set Session(conn) = oConn ors.open select * from t1,Session(conn),1,1 Response.write(Session(conn).ConnectionString) Response.write(<br/>) Response.write(TypeName(Session(conn))) ors.close Set ors = Nothing oConn.close Set oConn = Nothing %> |
This time, the ConnectionString property information can be displayed, and the result is also displayed that Session(conn) is the Connection object!
Original text: http://www.mzwu.com/article.asp?id=1105
Share: Windows 2003 Installation Settings iis Installation Chapter 2003: default installation without IIS. To install, please click Start -> Administrative Tools -> Configure Your Server Wizard and then step by step. It's time to select items on the list. Select the application server (IIS, ASP.NET) from the list