This example illustrates use of the StillExecuting property to monitor the progress of a query that is expected to take more than a few seconds. By enabling RDO's asynchronous mode, control returns to the application long before the query is complete. While waiting for the StillExecuting property to return False, we display a progress bar that has been programmed to reflect the length of time that the query is expected to take. Note that if this time is exceeded, the progress bar is re-calibrated to reflect the longer duration.
Dim rdoCn As New rdoConnection
Dim rdoRs As rdoResultset
Dim SQL As String
Dim TimeExpected As Single
Dim Ts As Single, Tn As Single
With rdoCn
.Connect = "UID=;PWD=;Database=WorkDB;" _
& "Server=SEQUEL;Driver={SQL Server}" _
& "DSN='';"
.LoginTimeout = 5
.EstablishConnection rdDriverNoPrompt, True
SQL = "Execute VeryLongProcedure"
TimeExpected = 20 ' We expect this to take 60 sec.
Set rdoRs = .OpenResultset(Name:=SQL, _
Type:=rdOpenForwardOnly, _
LockType:=rdConcurReadOnly, _
Option:=rdAsyncEnable)
Ts = Timer
ProgressBar1.Max = TimeExpected
While rdoRs.StillExecuting
Tn = Int(Timer - Ts)
If Tn < TimeExpected Then
ProgressBar1 = Tn
Else
ProgressBar1.Max = ProgressBar1.Max + 10
TimeExpected = ProgressBar1.Max
End If
DoEvents
Wend
Status = "Query done. Duration:" & Int(Timer - Ts)
End With
rdoRs.Close
rdoCn.Close