ASP Program Performance test report (iv)

Source: Internet
Author: User
Program | Performance v. Should you create a separate connection object when using recordsets?

To correctly answer this question, we must analyze the tests under two different conditions: first, the page has only one database transaction; second, the page has multiple database transactions.

In the previous precedent, we created a separate connection object and assigned it to the recordset's ActiveConnection property. However, as ado__03.asp shows, we can also assign the connection string directly to the ActiveConnection property, and the additional step of initializing and configuring the Connection object in the script can be omitted.

objrs.activeconnection = Application ("Conn")

Although the Recordset object still creates a connection, the creation at this time is done under highly optimized conditions. As a result, the page overhead has dropped by 23% compared to the previous test, and as expected, the display time for individual records has not changed materially.

Therefore, our second rule is as follows:

L Assign the connection string directly to the ActiveConnection property if only one recordset is used.

We then check whether the above rules are still valid when the page uses more than one recordset. To test this scenario, we introduce a for loop that repeats the precedent 10 times. In this test, we will look at three different changes:

First, as shown in ado__04.asp, create and dismantle connection objects in each cycle:

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, as shown in ado__05.asp, create the connection object outside the loop, and all recordsets share the object:

Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open application ("Conn")

Dim I
For i = 1 to 10
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

Next
Objconn.close
Set objconn = Nothing

Third, as shown in ado__06.asp, the connection string is assigned to the ActiveConnection property in each loop:

Dim I
For i = 1 to 10

Set objRS = Server.CreateObject ("ADODB. Recordset ")
objrs.activeconnection = Application ("Conn")
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
Next


As we can guess, creating and removing connection objects within a loop is the least efficient method. Amazingly, however, assigning a connection string directly to the ActiveConnection property within a loop is a little slower than sharing a single Connection object.

Nevertheless, the third rule should be:

L Create a single Connection object and share it with the ActiveConnection property when more than one recordset is used on the same page.



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.