Solved

Speed up Data Access

Posted on 2002-07-18
11
188 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
  • 6
  • 3
  • 2
11 Comments
 
LVL 4

Expert Comment

by:gencross
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
 

Author Comment

by:mutrus
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mutrus
Comment Utility
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 100 total points
Comment Utility
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
Comment Utility
Unbelieveable!!

Thanks
0
 

Author Comment

by:mutrus
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now