What is the best choice for improving ASP Performance (cont.)
Source: Internet
Author: User
Should you create a separate connection object when using a recordset?
To answer this question correctly, you need to test the results in two different situations: the first is to perform a database processing per page, and the second is to perform multiple database processing per page.
In the previous example, we have created a separate connection object and passed it to the ActiveConnection attribute of the recordset. However, it is also possible to simply pass the connection string into this property, thereby avoiding an additional step, which is to ado__03.asp and configure a separate component in the script:
objrs.activeconnection = Application ("Conn")
Although we still created a connection in the recordset, it was created in a very optimized scenario, so we started off with a 23% reduction in startup time, as expected, with almost no difference in the display time of each record.
So, our second rule is:
* When a single Recordset is used, the connection string is passed to the ActiveConnection property.
The following determines whether this logic still holds when multiple recordsets are created on a page. To test this, I introduced the For loop, repeating the previous example 10 times. In this test, we will also look at 3 options:
First, we create and destroy connection objects (ado__04.asp) in each loop:
Dim I
For i = 1 to 10
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open application ("Conn")
Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.activeconnection = objconn
Objrs.cursortype = 0 ' adopenforwardonly
Objrs.locktype = 1 ' adlockreadonly
Objrs.open application ("SQL")
If objrs.eof Then
Response.Write ("No Records Found")
Else
' Write headings
...
' Write Data
...
End If
Objrs.close
Set objRS = Nothing
Objconn.close
Set objconn = Nothing
Next
Second, create a separate connection object outside of the loop, and share it with each recordset (ado__05.asp):
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open application ("Conn")
Dim I
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