J
Jamie Collins
Consider the following code with executes a query asynchronously and
fetches its resultset asynchronously:
'---<Class 1>---
Option Explicit
Private WithEvents m_rs As ADODB.Recordset
Private Sub Class_Initialize()
Dim sql As String
sql = "<<Query goes here>>"
Set m_rs = New ADODB.Recordset
With m_rs
..ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<<file location goes here??"
..Source = sql
..Open , , , , adAsyncExecute + adAsyncFetch
End With
End Sub
Public Sub Cancel()
'If m_rs.State = adStateFetching Then
m_rs.Cancel
'End If
End Sub
'---</Class 1>---
'---<Module1>---
Option Explicit
Sub main()
Dim c1 As Class1
Set c1 = New Class1
Stop
c1.Cancel
End Sub
'---</Module1>---
The Stop is to pause the code, to prevent the execution being
cancelled before it has begun (i.e. paranoia <g>).
Replace "<<Query goes here>>" with a query (i.e. SQL that returns a
resultset) that takes long time to *execute*, as distinct from a query
that takes a long time to *fetch* the resultset.
When the code hits m_rs.Cancel it seems to become synchronous i.e. it
will cancel but only when the query has completed executing, which
could be a long wait! Same when setting the recordset to Nothing, same
when testing its State property. Using m_rs.ActiveConnection.Cancel
seems to have no effect.
Is this a limitation of the Access/Jet technology (OLE DB provider,
engine)? Cancelling works fine with SQL Server. Any workarounds?
Jamie.
--
fetches its resultset asynchronously:
'---<Class 1>---
Option Explicit
Private WithEvents m_rs As ADODB.Recordset
Private Sub Class_Initialize()
Dim sql As String
sql = "<<Query goes here>>"
Set m_rs = New ADODB.Recordset
With m_rs
..ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<<file location goes here??"
..Source = sql
..Open , , , , adAsyncExecute + adAsyncFetch
End With
End Sub
Public Sub Cancel()
'If m_rs.State = adStateFetching Then
m_rs.Cancel
'End If
End Sub
'---</Class 1>---
'---<Module1>---
Option Explicit
Sub main()
Dim c1 As Class1
Set c1 = New Class1
Stop
c1.Cancel
End Sub
'---</Module1>---
The Stop is to pause the code, to prevent the execution being
cancelled before it has begun (i.e. paranoia <g>).
Replace "<<Query goes here>>" with a query (i.e. SQL that returns a
resultset) that takes long time to *execute*, as distinct from a query
that takes a long time to *fetch* the resultset.
When the code hits m_rs.Cancel it seems to become synchronous i.e. it
will cancel but only when the query has completed executing, which
could be a long wait! Same when setting the recordset to Nothing, same
when testing its State property. Using m_rs.ActiveConnection.Cancel
seems to have no effect.
Is this a limitation of the Access/Jet technology (OLE DB provider,
engine)? Cancelling works fine with SQL Server. Any workarounds?
Jamie.
--