Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 GetRows and Disconnected Recordsets
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GauravBhabu
Advanced Member

4288 Posts

Posted - 27 November 2002 :  08:45:30  Show Profile
Disconnected Recordsets and GetRows method

Which is better and preferred?

Example:

<%
dim rstRecords, mySql, blnRecordsFound, fld
mySql = "SELECT FIELD1, FIELD2, FIELD3 FROM TESTTABLE;"


Rem -Disconnected Recordset Method

set rstRecords = server.createobject("adodb.recordset")
rstRecords.cursorlocation=aduseclient
rstRecords.open mySQL, my_Conn
Rem -disconnect the recordset
set rstRecords.activeconnection = nothing
if rstRecords.EOF then
  blnRecordsFound = false
else 
  blnRecordsFound = true
end if
if blnRecordsFound then
 do until rstRecords.EOF
  Response.write rstRecords("Field1") & "<BR />"
  Response.write rstRecords("Field2") & "<BR />"
  Response.write rstRecords("Field3") & "<BR /><BR />"
  rstRecords.MoveNext
 loop
end if
rstRecords.Close
Set rstRecords = nothing




Rem -GetRows method

dim arrRecords, iLoop
set rstRecords = server.createobject("adodb.recordset")
rstRecords.cursorlocation=aduseclient
rstRecords.open mySQL, my_Conn
Rem -disconnect the recordset
set rstRecords.activeconnection = nothing
if rstRecords.EOF then
  blnRecordsFound = false
else 
  blnRecordsFound = true
  arrRecords = rstRecords.getRows()
end if
rstRecords.Close
Set rstRecords = nothing
if blnRecordsFound then
 const field1 = 0
 const field2 = 1
 const field3 = 2
 for iLoop = 0 to ubound(arrRecords, 2)
   Response.write arrRecords(field1, iLoop) & "<BR />"
   Response.write arrRecords(field2, iLoop) & "<BR />"
   Response.write arrRecords(field3, iLoop) & "<BR />"
 next
end if
%>



Opinions Please:

1. How these two methods compare in terms of performance?
2. Advantages/Disadvantages of one method over the other








CSS and HTML4.01 Compilant Snitz Forum . ForumSquare . Rakesh Jain

It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.

Prayer Of Forgiveness
"I forgive all living beings. May all living beings forgive me!
I cherish the friendliness towards all and harbour enmity towards none." -- Aavashyaka Sutra(Translated)

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 27 November 2002 :  09:44:54  Show Profile  Visit HuwR's Homepage
using getrows is much faster, basically because data is placed in an array which ASP can deal with much quicker than extracting from the recordset object.
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 27 November 2002 :  10:04:57  Show Profile  Visit D3mon's Homepage
Getrows is fast, but can have problems if the number/order of fields changes unexpectedly (e.g. when using a SP)

Recordset is slower but allows referencing to the field name to retrieve data. Apparently, Using RS(0) instead of RS("[fieldname]") is faster in this instance because ASP has to use a 'lookup' table to discover the value of [fieldname] first (or something like that!)

I guess with 'disconnected' recordsets the DB resources are freed up just as early as the getrows version.

Recently, I've become a DRS > Getrows convert after witnessing the performance increases first hand.


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

Edited by - D3mon on 27 November 2002 10:05:46
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 27 November 2002 :  10:18:52  Show Profile  Visit HuwR's Homepage
yes, but accessing the the resulting array is still faster than looping through the recordset, look in the forums here, Bozden posted test results using various data access methods
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 27 November 2002 :  10:23:59  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
quote:
Originally posted by D3mon

Getrows is fast, but can have problems if the number/order of fields changes unexpectedly (e.g. when using a SP)

Recordset is slower but allows referencing to the field name to retrieve data. Apparently, Using RS(0) instead of RS("[fieldname]") is faster in this instance because ASP has to use a 'lookup' table to discover the value of [fieldname] first (or something like that!)



If you use ordinal values you will still get errors/incorrect values if something changes. I have become so use to GetRows I can't imagine using anything else.
quote:

set rstRecords.activeconnection = nothing
if rstRecords.EOF then
blnRecordsFound = false
else
blnRecordsFound = true
end if
if blnRecordsFound then
do until rstRecords.EOF
Response.write rstRecords("Field1") & "<BR />"
Response.write rstRecords("Field2") & "<BR />"
Response.write rstRecords("Field3") & "<BR /><BR />"
rstRecords.MoveNext
loop
end if
rstRecords.Close
Set rstRecords = nothing


I would imagine that being able to Close the rs and clear the rs earlier is better for overall performance. Although you are closing the connection early on, you are still looping through all your records before you rs.Close & set rs = Nothing. With getrows you do that right after array is built.

Also, with the array I believe it is a good habit to ERASE arrayname, which may or may not be the equivalent of set rs = nothing, I don't know.
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 27 November 2002 :  10:29:03  Show Profile  Visit D3mon's Homepage
Oh I agree completely HuwR.

What I'm wondering now is whether I'm wrong to use:

objConnection.execute(strSQL)


instead of:

ObjCommand.open strSQL


In fact I don't use the command object at all now. Is that bad/slow??


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

Edited by - D3mon on 27 November 2002 10:31:00
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 27 November 2002 :  11:11:06  Show Profile
quote:
Originally posted by HuwR

yes, but accessing the the resulting array is still faster than looping through the recordset, look in the forums here, Bozden posted test results using various data access methods



Did those tests included disconnected recordsets? I will look at the bozden's tests though.
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 27 November 2002 :  12:55:50  Show Profile
got time to look at the perforance tests. bozden tests show accessing arrays is faster.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.31 seconds. Powered By: Snitz Forums 2000 Version 3.4.07