Results 1 to 19 of 19

Thread: [RESOLVED] ADO v DAO - Why is DAO faster?

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved [RESOLVED] ADO v DAO - Why is DAO faster?

    I've always used ADO when using Access databases but just recently I've taken over a project where DAO has been used.

    I've extracted a module from the project to use is another project (which I started using ADO). The problem is the ADO code takes around 5 times longer than the DAO code.

    I have attached a sample project which shows how much quicker the DAO code completes compared to the ADO code. The database is a cut down version of what is used so 5 times longer can equal a long wait....

    Why would ADO be so much slower than DAO?
    Attached Files Attached Files
    Last edited by lintz; Oct 18th, 2006 at 01:46 AM.

  2. #2
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: ADO v DAO - Why is DAO faster?

    they arent being created the same way ..

    this line ...
    rs.Open sSQL, strcn, adOpenStatic, adLockPessimistic

    Change to this ..
    Set rs = strcn.Execute(sSQL, , adCmdText)

    Also Getrows would be even faster ..
    but thats for another day.

    Edit ... seems the connection gives an error ..
    The connection code is not being done correctly ..
    Last edited by rory; Oct 18th, 2006 at 02:41 AM.

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: ADO v DAO - Why is DAO faster?

    It is slower because your technique is all wrong. I am amazed that it worked at all. You are basically opening a connection to the database each time you open a recordset. Not a good idea.

    Try this:
    Attached Files Attached Files

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: ADO v DAO - Why is DAO faster?

    he got me lost with all that code with exclamations in it
    lintz, ADO is the successor to DAO BTW ..
    Opening a connection when you open the recordset is not the issue though.

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: ADO v DAO - Why is DAO faster?

    Quote Originally Posted by rory
    Opening a connection when you open the recordset is not the issue though.
    Really??? Did you look at the code I posted. That was basically the only change I made and look at the difference between the two times in his project and the one I posted.

  6. #6
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: ADO v DAO - Why is DAO faster?

    Quote Originally Posted by randem
    Really??? Did you look at the code I posted. That was basically the only change I made and look at the difference between the two times in his project and the one I posted.
    sorry my bad .. yeah i see now why he is getting the speed diff .
    Got a little lost up in that code is all .. 4am and all

  7. #7

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved Re: ADO v DAO - Why is DAO faster?

    Thanks randem

  8. #8
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    actually with all the tests above i was getting DAO as faster. ..
    But when i put ADO in front of DAO then i ADO was faster
    So basically its a timing issue ... is all.

    also you can speed that ADO up where you have loops, using GetRows ..
    And Stored Queries, as well as setting the variables ...

  9. #9

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    What is GetRows and how do I use them?

    So it's now 5am where you are

  10. #10
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    yeah 5am and im off to sleep in a minute, but basically get rows is like this ..
    Example using a Stored Query ..

    VB Code:
    1. Set objRs = objConn.Execute("Execute sq_MyQuery", , adCmdText)
    2.     If Not objRs.EOF Then
    3.         arr = objRs.GetRows()
    4.         Set objRs = Nothing
    5.         iCnt = UBound(arr, 2)
    6.         For i = 0 To iCnt
    7.             sField0 = arr(0, i)
    8.             sField1 = arr(1, i)
    9.             '// do something
    10.         Next i
    11.     Else
    12.         Set objRs = Nothing
    13.     End If

    Note - this is just one example of GetRows.
    Basically it lets you grab all the results into an array ..
    then just loop through the array.

    This partilcular method is proabably the fastest loop ..
    when you have alot of results ... it just spits it out at you.
    Last edited by rory; Oct 18th, 2006 at 04:38 AM.

  11. #11
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    There are other considerations other than speed for using ado over dao, such as possible future database migration.

    And to speed things up, you might want to consider using aggregates such as Sum() rather than iterating through recordsets.

  12. #12

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    Nice one leinad31, using SUm will definately fasten it up for me!

  13. #13
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,944

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    Quote Originally Posted by rory View Post
    yeah 5am and im off to sleep in a minute, but basically get rows is like this ..
    Example using a Stored Query ..

    VB Code:
    1. Set objRs = objConn.Execute("Execute sq_MyQuery", , adCmdText)
    2.     If Not objRs.EOF Then
    3.         arr = objRs.GetRows()
    4.         Set objRs = Nothing
    5.         iCnt = UBound(arr, 2)
    6.         For i = 0 To iCnt
    7.             sField0 = arr(0, i)
    8.             sField1 = arr(1, i)
    9.             '// do something
    10.         Next i
    11.     Else
    12.         Set objRs = Nothing
    13.     End If

    Note - this is just one example of GetRows.
    Basically it lets you grab all the results into an array ..
    then just loop through the array.

    This partilcular method is proabably the fastest loop ..
    when you have alot of results ... it just spits it out at you.
    hi Roy....
    but during the loop in array is possible to know wath is the current filed name ...
    similar:
    Code:
       Set objRs = objConn.Execute("Execute sq_MyQuery", , adCmdText)
        If Not objRs.EOF Then
            arr = objRs.GetRows()
            Set objRs = Nothing
            iCnt = UBound(arr, 2)
            For i = 0 To iCnt
                sField0 = arr(0, i)
    debug.print namefiled of sField0
                sField1 = arr(1, i)
    debug.print namefiled of sField1
                '// do something 
            Next i
        Else
            Set objRs = Nothing
        End If
    Last edited by Hack; Mar 31st, 2009 at 09:51 AM.

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    Like this:
    Code:
    debug.print objRs.Fields(i).Name
    By the way, rather than replying to this old thread (and thus sending emails to everyone who has replied/subscribed) you should have posted a new thread.

  15. #15
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,944

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    Quote Originally Posted by si_the_geek View Post
    Like this:
    Code:
    debug.print objRs.Fields(i).Name
    By the way, rather than replying to this old thread (and thus sending emails to everyone who has replied/subscribed) you should have posted a new thread.
    Sorry for:
    By the way, rather than replying to this old thread (and thus sending emails to everyone who has replied/subscribed) you should have posted a new thread.

    tks for explain

    but really my qst is:

    is possible to decide wath filed get from getrows array???

    i dont need to gett all fileds from the statement but only PROVA1, PROVA3, ecc...

    similar:
    arrResults = RSSQL2.GetRows(PROVA1, PROVA3...ecc)

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    Specify the fields you want in the SQL statement, eg:
    Code:
    SELECT Prova1, Prova3 FROM tablename ...

  17. #17
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,944

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    Quote Originally Posted by si_the_geek View Post
    Specify the fields you want in the SQL statement, eg:
    Code:
    SELECT Prova1, Prova3 FROM tablename ...
    ok! tks.

  18. #18
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    is possible to decide wath filed get from getrows array???
    i dont need to gett all fileds from the statement but only PROVA1, PROVA3, ecc...
    To specify which fields you want to be included in the Array use the 3rd argument of the GetRows method. The 3rd argument accepts an array of fieldnames or ordinal positions (or a single field/position).

    Dim arrResults As Variant
    arrResults = rsData.GetRows(, , Array("PROVA1", "PROVA3"))
    arrResults = rsData.GetRows(, , Array(0, 2))

  19. #19
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,944

    Re: [RESOLVED] ADO v DAO - Why is DAO faster?

    Quote Originally Posted by brucevde View Post
    To specify which fields you want to be included in the Array use the 3rd argument of the GetRows method. The 3rd argument accepts an array of fieldnames or ordinal positions (or a single field/position).

    Dim arrResults As Variant
    arrResults = rsData.GetRows(, , Array("PROVA1", "PROVA3"))
    arrResults = rsData.GetRows(, , Array(0, 2))
    tks Bruce & si_the_geek!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width