[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Fetching Data Asynchronously and progress bar

Posted on 2001-06-11
5
Medium Priority
?
1,345 Views
Last Modified: 2012-08-14
This is a two part question but related:

1. WHat is the difference between fetching data asynchronously as opposed to synchronously.

2. Which brings me to this question: I bought a code snippet on using a progress bar for two things: one to show how long it takes the records to be brought back from the database, adn the other is processing those records.. this is what I came up with.

Private WithEvents cnnSQL As ADODB.Connection
Private WithEvents rs As ADODB.Recordset

Private Sub Command1_Click()
   Dim maxrecords As Long
   
   Set cnnSQL = New ADODB.Connection
   Set rs = New ADODB.Recordset
   mydsn = "DSN=ARSystem3;uid=myid;pwd=mypwd"
   cnnSQL.Open mydsn
   
   rs.Open "data_count_sel(965520000, 966124799)", cnnSQL
   maxrecords = rs("recordcount")
   rs.Close
   
   ProgressBar1.Max = maxrecords
   
   
   rs.CursorLocation = adUseClient
   rs.Open "data_sel(965520000, 966124799)", cnnSQL, adOpenStatic, adLockReadOnly, adAsyncFetch
   Do While rs.State <> adStateOpen
       DoEvents
   Loop
   ProgressBar1.Value = 0
   Dim i As Long
   i = 0
   Do Until rs.EOF
   i = i + 1
   ProgressBar1.Value = i
   rs.MoveNext
   
   Loop
   
   
   rs.Close
   cnnSQL.Close
   Set rs = Nothing
   Set cnnSQL = Nothing
End Sub

Private Sub Command2_Click()
   rs.Cancel
End Sub

Private Sub rs_FetchProgress(ByVal Progress As Long, ByVal MaxProgress As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
   ProgressBar1.Value = Progress
   
   
   'lblprogress.Caption = "Records Fetched: " & Progress & " / " & MaxProgress
End Sub


The progress bar works for both .. I just want to make sure that this is the most efficient way of processing this code. I don't wnat to just copy the work, i want to learn it.. Here are some code snippets I would like to understand what is happening..

'WHat I think is happening is it is the point in time
'where the data is being fetched, up until the recordset
'is actually populated..

Do While rs.State <> adStateOpen
       DoEvents
Loop


How and where does this get called. And what other things could this be used for...
Private Sub rs_FetchProgress(ByVal Progress As Long, ByVal MaxProgress As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
   ProgressBar1.Value = Progress
   
   
   'lblprogress.Caption = "Records Fetched: " & Progress & " / " & MaxProgress
End Sub

I think this is a fairly easy question, but because of the length of it, I will post as moderate..


thanks for the help
0
Comment
Question by:tchous
[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
5 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6177592
1.  async lets your program go about its business while it is getting the records while sync makes you wait until all records come back before doing anything else
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6177625
in the great words of msdn it says that the fetchprogress gets called "periodically" while fetching records to report progress...You would think they could be a little more specific.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6177838
<ping>
0
 

Accepted Solution

by:
bosley earned 300 total points
ID: 6178784
As said before, "1.  async lets your program go about its business while it is getting the records while sync makes you wait until all records come back before doing anything else"

If you want to show progress you need to use async processing.

The code...

Do While rs.State <> adStateOpen
      DoEvents
Loop

...will loop unitl the recordset has completed the retrieval. During the time the retrieval is happening the event rs_FetchProgress will fire periodically.  The values "Progress As Long" is the number of records that have currently been retrieved, "MaxProgress As Long" is the max number of records expected to be retrieved.  These are the values you would use in the rs_FetchProgress event to update your progress bar.

Because the rs_FetchProgress event fires only periodically Async processing in this manner is really only useful for the retrieval of large recordsets because if the recordset is small you won't have to wait at all for the retrieval to be complete thus really no need to give the user progress.

Hope this helps.

bosley

0
 

Author Comment

by:tchous
ID: 6178832
Thanks for the further information..
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

649 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