N
Nick Stansbury
Hi,
I'm using the following code to fetch a results set from a sql server
database based on the other side of the world to the client - so there's
some delay in fetching large recordset (1000 records+). The most resource
effecient method appears to be to use a client-side cursor and fetch a
static disconnected recordset. When the command executs I show a little
pop-up status window - and it's this window thats causing me all of the
trouble.
Here's the code:
Public Function OpenDisconnectedRecordset(Command As ADODB.Command) As
ADODB.Recordset
DisplayStatusMessageOnPopUpForm "Preparing results set"
Dim rs As New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CacheSize = 10
DisplayStatusMessageOnPopUpForm "Opening results set"
rs.Open Command, , adOpenStatic, adLockReadOnly, adAsyncFetch
Dim i As Integer
i = 0
While rs.State > adStateOpen
DisplayStatusMessageOnPopUpForm "Fetching additional results - " +
CStr(i) + " fetched so far"
StepProgressBarOnPopUpForm
i = i + 1
If CheckQueryCancelled() = True Then
rs.ActiveCommand.Cancel
End If
Wend
DisplayStatusMessageOnPopUpForm "Results set full - closing connection"
rs.ActiveConnection = Nothing
Set OpenDisconnectedRecordset = rs
End Function
Now what I'd like to do is show on a little "popup" window the total number
of records fetched so far, the total number of records to be fetched, the
estimated time left, and a progress bar representing exactly that. I'd also
like the pop-up window to have the capacity to "cancel" the running query.
There are three problems -
1) How do you find out how many records have been fetched by an async
fetched recordsed at any given point in time? I've tried getting the record
count - but that fetches every record down counts them - rather than telling
you how many have been returned so far. Is there anyway to achieve this? The
way I'm doing it above is a total fake - it's just counting the number of
iterations through a random loop - the number is totally meaningless.
2) There's no way I can see of returning the total recordcount *before* the
results set - output parameters (which are the obvious choice) are only
returned at the end of the stream from the database - so you can't get to
their values until you've returned any and all results sets in full. Anyway
around this? Any ideas how I could achieve this? I'd like to avoid a second
database call if possible.
3) A cancel button on the popup form just doesn't seem to work. What I was
hoping was that I could put a cancel button on my little pop-up, use it's
event handler to set a boolean flag to cancelled, and then use the
"CheckQueryCancelled" call above to catch the condition and cancel the
query. I know that I'm trying to fake some sort of threaded behaviour here -
and it just isn't working. The command button just plain doesn't work (it
doesn't "depress" when clicked, no events fire etc.) whilst the other code
is running. Any ideas here?
Any and all help would be very gratefully received!
Nick
I'm using the following code to fetch a results set from a sql server
database based on the other side of the world to the client - so there's
some delay in fetching large recordset (1000 records+). The most resource
effecient method appears to be to use a client-side cursor and fetch a
static disconnected recordset. When the command executs I show a little
pop-up status window - and it's this window thats causing me all of the
trouble.
Here's the code:
Public Function OpenDisconnectedRecordset(Command As ADODB.Command) As
ADODB.Recordset
DisplayStatusMessageOnPopUpForm "Preparing results set"
Dim rs As New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CacheSize = 10
DisplayStatusMessageOnPopUpForm "Opening results set"
rs.Open Command, , adOpenStatic, adLockReadOnly, adAsyncFetch
Dim i As Integer
i = 0
While rs.State > adStateOpen
DisplayStatusMessageOnPopUpForm "Fetching additional results - " +
CStr(i) + " fetched so far"
StepProgressBarOnPopUpForm
i = i + 1
If CheckQueryCancelled() = True Then
rs.ActiveCommand.Cancel
End If
Wend
DisplayStatusMessageOnPopUpForm "Results set full - closing connection"
rs.ActiveConnection = Nothing
Set OpenDisconnectedRecordset = rs
End Function
Now what I'd like to do is show on a little "popup" window the total number
of records fetched so far, the total number of records to be fetched, the
estimated time left, and a progress bar representing exactly that. I'd also
like the pop-up window to have the capacity to "cancel" the running query.
There are three problems -
1) How do you find out how many records have been fetched by an async
fetched recordsed at any given point in time? I've tried getting the record
count - but that fetches every record down counts them - rather than telling
you how many have been returned so far. Is there anyway to achieve this? The
way I'm doing it above is a total fake - it's just counting the number of
iterations through a random loop - the number is totally meaningless.
2) There's no way I can see of returning the total recordcount *before* the
results set - output parameters (which are the obvious choice) are only
returned at the end of the stream from the database - so you can't get to
their values until you've returned any and all results sets in full. Anyway
around this? Any ideas how I could achieve this? I'd like to avoid a second
database call if possible.
3) A cancel button on the popup form just doesn't seem to work. What I was
hoping was that I could put a cancel button on my little pop-up, use it's
event handler to set a boolean flag to cancelled, and then use the
"CheckQueryCancelled" call above to catch the condition and cancel the
query. I know that I'm trying to fake some sort of threaded behaviour here -
and it just isn't working. The command button just plain doesn't work (it
doesn't "depress" when clicked, no events fire etc.) whilst the other code
is running. Any ideas here?
Any and all help would be very gratefully received!
Nick