Results 1 to 17 of 17

Thread: [RESOLVED] Slow Database retreivals

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Resolved [RESOLVED] Slow Database retreivals

    Hello,

    This is my first post on here and am in need of some advice. I normally work with Oracle databases but have been asked to write a VB6/MS Access program.

    Im using Visual Basic 6.0 Professional. Using Visual Data Manager v6.0. Im using data1.recordset usage to access the data. The only large table I have has 5000 records and it takes approximately 1 minute to load the initial window with all these records. I have tried to create indexes on the fields which I think will be in the "where" clause, as in Oracle, but response is still slow.

    My question is, what am I doing wrong and how do I see the "pure SQL" like SELECT name FROM customer WHERE name="Hibbs", using VB so I can create the index accordingly?

    Many Thanks.


  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Slow Database retreivals

    Short answer: Don't use the VDM.
    Longer answer... code the queries yourself, or build the views right in the Access database and query those.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    So I should use MS Access instead or convert the VDM to Access?
    Have you got an example code that I can view for the information given below?

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

    Re: Slow Database retreivals

    Welcome to the Forums!

    Instead of using VDM or Data Controls, I would recommend creating the connections/recordsets yourself - you have far more control over what happens, and you can use SQL for virtually every piece of work you do with the database.

    A good way to go is ADODB, as this should be supported for a long time (including in the next version of Windows). You can find a good example of the basics in the "ADO Tutorial" link in my signature.

    As for Indexes, try not to have too many as they can slow things down if you go OTT - just have the ones that are most relevant (eg: primary keys).

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Slow Database retreivals

    Quote Originally Posted by Rudie
    The only large table I have has 5000 records and it takes approximately 1 minute to load the initial window with all these records.
    Why are you loading them all at once?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    Im loading all the records into a list box cos I need to show all the customers that are in debt, credit etc. up to 5000 records.

    Also, is there a faster way to select/deselect all the records within a listbox?

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Slow Database retreivals

    Quote Originally Posted by Rudie
    Also, is there a faster way to select/deselect all the records within a listbox?
    Welcome to the forums.
    VB Code:
    1. Private Sub cmdSelectAll_Click()
    2. Dim i As Long
    3. For i = 0 To List1.ListCount - 1
    4.     List1.Selected(i) = True
    5. Next
    6. End Sub
    7.  
    8. Private Sub cmdUnSelectAll_Click()
    9. Dim i As Long
    10. For i = 0 To List1.ListCount - 1
    11.     List1.Selected(i) = False
    12. Next
    13. End Sub

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    Thanks for this Hack, but I forgot to add that this takes ages on 5000 records. As it has to go through each one in the listbox. Does anyone know of a faster way?

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Slow Database retreivals

    Quote Originally Posted by Rudie
    Thanks for this Hack, but I forgot to add that this takes ages on 5000 records. As it has to go through each one in the listbox. Does anyone know of a faster way?
    Try this
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    2. (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    3. lParam As Any) As Long
    4.  
    5. Private Const LB_SETSEL = &H185&
    6.  
    7. Private Sub cmdSelectAll_Click()
    8. Call SendMessage(List1.hwnd, LB_SETSEL, True, ByVal -1)
    9. End Sub
    10.  
    11. Private Sub cmdUnSelectAll_Click()
    12. Call SendMessage(List1.hwnd, LB_SETSEL, False, ByVal -1)
    13. End Sub

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    Thanks, that works excellent - select/deselect.

    Ive managed to come up with a solution for the slow loading rather than recoding. Im refreshing the listbox every 100 records so at least it loads every couple of seconds rather than hanging for half a minute.

    Next problem is that ive created a window to show to progress using the progressbar1, but how do i continue to load the listbox and control the progressbar at the same time?

    At the moment, when the progress bar is progressing back and forth, the listbox is not loading until the progress window is closed.

    Ive set an Interval on the Timer of 10

    Within the Timer event, I got 'DoEvents' which I thought would release the loop to other processes.

    Is what I am trying possible?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Slow Database retreivals

    Post what you are doing. I'd like to take a look.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    Not sure whast you mean mate, do you mean screenshots or code shots?

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Slow Database retreivals

    Quote Originally Posted by Rudie
    Not sure whast you mean mate, do you mean screenshots or code shots?
    Your code. Like I posted listbox code as an example. I want to see the code you are using to do your record loading and progress bar showing. To make things easier to ready, please encapsulate your code in [vbcode][/vbcode] tags. (See my signature)

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    Heres the progress bar code that will go back and forth
    VB Code:
    1. Private Sub Timer1_Timer()
    2. 'This procedure will show the progress while its printing
    3. On Error Resume Next
    4.     'Increment the progress bar
    5.     If check = 0 Then
    6.         ProgressBar1.Value = ProgressBar1.Value + 1
    7.         If ProgressBar1.Value >= 100 Then
    8.             check = 1
    9.             countr = countr + 1
    10.         End If
    11.     Else
    12.         ProgressBar1.Value = ProgressBar1.Value - 1
    13.         If ProgressBar1.Value <= 0 Then
    14.             check = 0
    15.             countr = countr + 1
    16.         End If
    17.     End If
    18.     DoEvents
    19. End Sub

    I want to call this to start this off but want to load the listbox within another form whilst showing the above...

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Slow Database retreivals

    Quote Originally Posted by Rudie
    I want to call this to start this off but want to load the listbox within another form whilst showing the above...
    Ah...didn't actually need to see the code after all. I just needed to know this.

    These are two separate activities each of which will execute within the same memory thread (VB does not do multithreading). Therefore, one can not execute until the other is finished. You would need to combine the two into a single routine in which the records where loading, and within the loop you have for that, your would progress your progressbar.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    Ok, I see what I will have to do. I will have to incorporate the above within the listbox loading. I currently have a seperate window to control the progressbar, but can easily have that on the same window and make it visible/invisible.


    I will let you know how I get on. Thanks to everyone for their help.


  17. #17

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    Birmingham, England.
    Posts
    115

    Re: Slow Database retreivals

    Sorted, as per Hack's reply.

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