?
Solved

Speed up Data Access

Posted on 2002-07-18
11
Medium Priority
?
202 Views
Last Modified: 2010-05-02
The code below populates treeview with data from an Access Db.

It is quite slow over a network. Is there a way of speeding up this process?

[Code]
If gcDB.CreateRS(oRsContacts, strSQLContacts) Then
    If oRsContacts.RecordCount Then
        Do While Not oRsContacts.EOF
            Set oTmpNode = TView.Nodes.add("Contacts", tvwChild, "Contact_" & oRsContacts.Fields("ConNo"), oRsContacts.Fields("ConCompany"))
            TView.Nodes("Contact_" & oRsContacts.Fields("ConNo")).Tag = "Contact"
            If gcDB.CreateRS(oRsProjectsData, strSQLContactData) Then
                Do While Not oRsProjectsData.EOF
                    Set oTmpNode = TView.Nodes.add("Contact_" & oRsContacts.Fields("ConNo"), tvwChild, "ProjectData_" & oRsProjectsData.Fields("ID"), oRsProjectsData.Fields("ProjectName"))
                    TView.Nodes("ProjectData_" & oRsProjectsData.Fields("ID")).Tag = "Project"
                    oRsProjectsData.MoveNext
                Loop
            End If
            oRsContacts.MoveNext
        Loop
    End If
End If
0
Comment
Question by:mutrus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7163272
It looks like you are setting a node object then not using it...

You can also use 'With...End With'.

Here is your code with the above changes...

If gcDB.CreateRS(oRsContacts, strSQLContacts) Then
    With oRsContacts
        If .RecordCount Then
            Do While Not oRsContacts.EOF
                Set oTmpNode = TView.Nodes.Add("Contacts", tvwChild, "Contact_" & .Fields("ConNo"), .Fields("ConCompany"))
                oTmpNode.Tag = "Contact"
                If gcDB.CreateRS(oRsProjectsData, strSQLContactData) Then
                    Do While Not oRsProjectsData.EOF
                        Set oTmpNode = TView.Nodes.Add("Contact_" & .Fields("ConNo"), tvwChild, "ProjectData_" & oRsProjectsData.Fields("ID"), oRsProjectsData.Fields("ProjectName"))
                        oTmpNode.Tag = "Project"
                        oRsProjectsData.MoveNext
                    Loop
                End If
                oRsContacts.MoveNext
            Loop
        End If
    End With
End If

NOTE: Be sure to open the recordsets forward only, read only.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7163283
I forgot to take out a couple of references to oRsContacts...

Do While Not oRsContacts.EOF

Should be: Do While Not .EOF

oRsContacts.MoveNext

Should be: .MoveNext

Remove any other references to oRsContacts that I missed.


0
 

Author Comment

by:mutrus
ID: 7163441
>>NOTE: Be sure to open the recordsets forward only, read only

This is the class code for CreateRS. Is this what you mean by your statement?

    Dim oCmd As ADODB.Command

    Set goRs = New ADODB.Recordset
    Set oCmd = New ADODB.Command
    Set oCmd.ActiveConnection = moCon
    oCmd.CommandText = SQL
    With goRs
        .CursorLocation = ADODB.adUseClient
        .StayInSync = True
        .CacheSize = 1
        .Open oCmd, , ADODB.adOpenDynamic, ADODB.adLockBatchOptimistic
    End With
    CreateRS = True
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:mutrus
ID: 7163483
Tried your changes - not much of a difference

improvement of only 1 second with 30 records in outer loop and two records each in inner loop. Total time to load 7 seconds



0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7163497
What is the variable "SQL" in you code?

If all it is, is a SQL statement then try this:
Set goRs = New ADODB.Recordset
With goRs
   .Source = SQL
   Set ActiveConnection = moCon
   .CursorType = adOpenForwardOnly
   .LockType = adLockReadOnly
   .Open Options:=adCmdText
End With

Anthony
0
 

Author Comment

by:mutrus
ID: 7163582
acperkins - thanks for suggestion but this would involve changing a huge amount of code due to me using a ADO class wrapper. If I still cannot solve the speed problem using some other means (I tend to think its the network) then I'll come back to your suggestion
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 400 total points
ID: 7163622
Ok. But can you not even change this one line:
.Open oCmd, ,ADODB.adOpenDynamic, ADODB.adLockBatchOptimistic

To this:
.Open oCmd, , adOpenForwardOnly, adLockReadOnly

Anthony
0
 

Author Comment

by:mutrus
ID: 7163698
Unbelieveable!!

Thanks
0
 

Author Comment

by:mutrus
ID: 7163711
acperkins

Can you expalain in laymans terms if possible the difference between my original code and your solutions

Thanks
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7163739
First of all I do not believe I deserve the credit, if you notice gencross had previously suggested it.

But to answer your question a cursor type of adOpenDynamic is the most expensive type of cursor available.  It supports bookmarking (this allows you to go back and forward in the cursor) and updates. Not all providers support it, but they will degrade to the next option.

Here is an article from MSDN that goes into more length:
Understanding ADO's Default Cursor Type
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnima01/html/ima0501.asp

Also, depending on your provider you may see improvements if you change:
.CursorLocation = adUseClient
to
.CursorLocation = adUseServer

Anthony
0
 

Author Comment

by:mutrus
ID: 7170551
acperkins - thanks for the article. and yes you are right, I see gencross's note now


gencross - have posted some points for you - thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question