The following are the referenced contents: <% 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 online spread of the connection object to save the code in the Seesion object, note that: session ("conn") = oconn, the object of replication is such a son? Let's verify this below:
The following are the referenced contents: <% 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 %> |
Result error, prompt "Missing object: ' Session (...) '"! This indicates that the object did not replicate successfully, what type of session ("Conn") is it? We use TypeName ("conn") to test, the result is "String"! Out of curiosity, we output the session directly ("conn") to see:
The following are the referenced contents: <% 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 results are:
The following are the referenced contents: 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 |
Is this not a ConnectionString property value for the connection object? The default property of the Connection object is connectionstring, and performing session ("conn") = Oconn only assigns the value of the Connection object default property to the session ("Conn"). Why is it used in the oRS.Open "select * from T1", the session ("Conn"), 1,1 can also succeed? Find data The second parameter of the Open method of the Recordset object can be either a connection object or a string of database connection information! OK, the Oconn object in the above example is completely superfluous, directly using the following code:
The following are the referenced contents: <% 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 %> |
There is nothing wrong with the result. Okay, so far, there's one problem left unresolved: How is the correct object-copying method? Or use the SET statement:
The following are the referenced contents: <% 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 ("conn")) Ors.close Set ors = Nothing Oconn.close Set oconn = Nothing %> |
This time can display the ConnectionString attribute information, the result also shows session ("Conn") for connection Object!
Original: http://www.mzwu.com/article.asp?id=1105