Solved

Speed up Data Access

Posted on 2002-07-18
11
193 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 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