How to execute an ADO query asynchronously?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default How to execute an ADO query asynchronously?

    Is this a valid code (running in a COM+ component)?

    VB class (MTSTransactionMode = 1 - NoTransactions):

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Implements ObjectControl

    Private ObjCtx As ObjectContext
    Private ASPReq As ASPTypeLibrary.Request
    Private ASPRes As ASPTypeLibrary.Response
    Private ASPSer As ASPTypeLibrary.Server

    Private Sub ObjectControl_Activate()

    On Error Resume Next

    Set ObjCtx = GetObjectContext()
    Set ASPReq = ObjCtx("Request")
    Set ASPRes = ObjCtx("Response")
    Set ASPSer = ObjCtx("Server")

    End Sub

    Private Function ObjectControl_CanBePooled() As Boolean
    ObjectControl_CanBePooled = False
    End Function

    Private Sub ObjectControl_Deactivate()

    On Error Resume Next

    Set ObjCtx = Nothing
    Set ASPReq = Nothing
    Set ASPRes = Nothing
    Set ASPSer = Nothing

    End Sub

    Public Sub RunQueryAsync()

    On Error GoTo Run_Err

    Dim cx As Connection
    Dim rs As Recordset

    Set cx = New Connection
    cx.CursorLocation = adUseServer
    cx.ConnectionString = "Provider=sqloledb;server=..."
    cx.Open

    ' Execute long query
    Set rs = cx.Execute("exec pa_longquery", , adAsyncExecute)

    Do Until rs.State <= 1
    ' If client is not connected then cancel query and exit
    If Not ASPRes.IsClientConnected Then
    cx.Cancel ' Cancel query
    Err.Raise vbObjectError + 512, "", "The client has disconnected"
    End If
    ' Wait
    Sleep 100
    Loop

    ' Return data to client
    ASPRes.Write rs.GetString

    ' Ok
    ObjCtx.SetComplete

    Run_Exit:
    If rs.State <> 0 Then rs.Close
    Set rs = Nothing
    cx.Close
    Set cx = Nothing

    Exit Sub

    Run_Err:
    On Error Resume Next
    ASPRes.Write "¡¡ERROR!! " & Err.Description
    ObjCtx.SetAbort
    Resume Run_Exit

    End Sub

    Pros, contras, performance, ideas....

    Thanks.


    kibokochui Guest

  2. Similar Questions and Discussions

    1. Execute Query on trigger
      Hi, I want to 2 link to drop down menus together so that the options from the second will be filtered according to the option chose in the first...
    2. How to execute 2 sql commands in one sql query?
      Hello, I need to delete some records and insert new ones right away. Is there any way to do it within the same query string? Set objRecordset =...
    3. Asynchronously executing query ?
      I have been searching for an anser to this but it seems it is not a commonly used technique. If I execute a long running sp or query...
    4. how to execute the query with special character
      hello, i am using command window on db2 udb v8.1 on windows to query a table with field name like this select abc\ from table, but i get the error...
    5. Execute Query in Access from an ASP Form?
      Hi, I have an Access database with a query that selects a set of records from one table (work categories) and inserts them (multiple rows) in to...
  3. #2

    Default Re: How to execute an ADO query asynchronously?

    You can use an asynchronous flag with ADO, however it doesn't make much
    sense if that query needs to return data to the client.
    [url]http://www.aspfaq.com/2194[/url]

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]




    "kibokochui" <No@mail> wrote in message
    news:O1bKr4Y4DHA.1644@TK2MSFTNGP10.phx.gbl...
    > Is this a valid code (running in a COM+ component)?
    >
    > VB class (MTSTransactionMode = 1 - NoTransactions):
    >
    > Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    >
    > Implements ObjectControl
    >
    > Private ObjCtx As ObjectContext
    > Private ASPReq As ASPTypeLibrary.Request
    > Private ASPRes As ASPTypeLibrary.Response
    > Private ASPSer As ASPTypeLibrary.Server
    >
    > Private Sub ObjectControl_Activate()
    >
    > On Error Resume Next
    >
    > Set ObjCtx = GetObjectContext()
    > Set ASPReq = ObjCtx("Request")
    > Set ASPRes = ObjCtx("Response")
    > Set ASPSer = ObjCtx("Server")
    >
    > End Sub
    >
    > Private Function ObjectControl_CanBePooled() As Boolean
    > ObjectControl_CanBePooled = False
    > End Function
    >
    > Private Sub ObjectControl_Deactivate()
    >
    > On Error Resume Next
    >
    > Set ObjCtx = Nothing
    > Set ASPReq = Nothing
    > Set ASPRes = Nothing
    > Set ASPSer = Nothing
    >
    > End Sub
    >
    > Public Sub RunQueryAsync()
    >
    > On Error GoTo Run_Err
    >
    > Dim cx As Connection
    > Dim rs As Recordset
    >
    > Set cx = New Connection
    > cx.CursorLocation = adUseServer
    > cx.ConnectionString = "Provider=sqloledb;server=..."
    > cx.Open
    >
    > ' Execute long query
    > Set rs = cx.Execute("exec pa_longquery", , adAsyncExecute)
    >
    > Do Until rs.State <= 1
    > ' If client is not connected then cancel query and exit
    > If Not ASPRes.IsClientConnected Then
    > cx.Cancel ' Cancel query
    > Err.Raise vbObjectError + 512, "", "The client has disconnected"
    > End If
    > ' Wait
    > Sleep 100
    > Loop
    >
    > ' Return data to client
    > ASPRes.Write rs.GetString
    >
    > ' Ok
    > ObjCtx.SetComplete
    >
    > Run_Exit:
    > If rs.State <> 0 Then rs.Close
    > Set rs = Nothing
    > cx.Close
    > Set cx = Nothing
    >
    > Exit Sub
    >
    > Run_Err:
    > On Error Resume Next
    > ASPRes.Write "¡¡ERROR!! " & Err.Description
    > ObjCtx.SetAbort
    > Resume Run_Exit
    >
    > End Sub
    >
    > Pros, contras, performance, ideas....
    >
    > Thanks.
    >
    >

    Aaron Bertrand [MVP] Guest

  4. #3

    Default Re: How to execute an ADO query asynchronously?

    In my case, querys always return data to the client.
    I want to execute them asynchronously to offer to the user the possibility
    of cancelling them.

    Thanks.

    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> escribió en el mensaje
    news:OTIDEgb4DHA.2168@TK2MSFTNGP12.phx.gbl...
    > You can use an asynchronous flag with ADO, however it doesn't make much
    > sense if that query needs to return data to the client.
    > [url]http://www.aspfaq.com/2194[/url]
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > [url]http://www.aspfaq.com/[/url]
    >
    >
    >
    >
    > "kibokochui" <No@mail> wrote in message
    > news:O1bKr4Y4DHA.1644@TK2MSFTNGP10.phx.gbl...
    > > Is this a valid code (running in a COM+ component)?
    > >
    > > VB class (MTSTransactionMode = 1 - NoTransactions):
    > >
    > > Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    > >
    > > Implements ObjectControl
    > >
    > > Private ObjCtx As ObjectContext
    > > Private ASPReq As ASPTypeLibrary.Request
    > > Private ASPRes As ASPTypeLibrary.Response
    > > Private ASPSer As ASPTypeLibrary.Server
    > >
    > > Private Sub ObjectControl_Activate()
    > >
    > > On Error Resume Next
    > >
    > > Set ObjCtx = GetObjectContext()
    > > Set ASPReq = ObjCtx("Request")
    > > Set ASPRes = ObjCtx("Response")
    > > Set ASPSer = ObjCtx("Server")
    > >
    > > End Sub
    > >
    > > Private Function ObjectControl_CanBePooled() As Boolean
    > > ObjectControl_CanBePooled = False
    > > End Function
    > >
    > > Private Sub ObjectControl_Deactivate()
    > >
    > > On Error Resume Next
    > >
    > > Set ObjCtx = Nothing
    > > Set ASPReq = Nothing
    > > Set ASPRes = Nothing
    > > Set ASPSer = Nothing
    > >
    > > End Sub
    > >
    > > Public Sub RunQueryAsync()
    > >
    > > On Error GoTo Run_Err
    > >
    > > Dim cx As Connection
    > > Dim rs As Recordset
    > >
    > > Set cx = New Connection
    > > cx.CursorLocation = adUseServer
    > > cx.ConnectionString = "Provider=sqloledb;server=..."
    > > cx.Open
    > >
    > > ' Execute long query
    > > Set rs = cx.Execute("exec pa_longquery", , adAsyncExecute)
    > >
    > > Do Until rs.State <= 1
    > > ' If client is not connected then cancel query and exit
    > > If Not ASPRes.IsClientConnected Then
    > > cx.Cancel ' Cancel query
    > > Err.Raise vbObjectError + 512, "", "The client has
    disconnected"
    > > End If
    > > ' Wait
    > > Sleep 100
    > > Loop
    > >
    > > ' Return data to client
    > > ASPRes.Write rs.GetString
    > >
    > > ' Ok
    > > ObjCtx.SetComplete
    > >
    > > Run_Exit:
    > > If rs.State <> 0 Then rs.Close
    > > Set rs = Nothing
    > > cx.Close
    > > Set cx = Nothing
    > >
    > > Exit Sub
    > >
    > > Run_Err:
    > > On Error Resume Next
    > > ASPRes.Write "¡¡ERROR!! " & Err.Description
    > > ObjCtx.SetAbort
    > > Resume Run_Exit
    > >
    > > End Sub
    > >
    > > Pros, contras, performance, ideas....
    > >
    > > Thanks.
    > >
    > >
    >
    >

    kibokochui Guest

  5. #4

    Default Re: How to execute an ADO query asynchronously?

    > In my case, querys always return data to the client.
    > I want to execute them asynchronously to offer to the user the possibility
    > of cancelling them.
    That's not what asynchronous is for. Checks to Response.isClientConnected
    can allow you to cancel your query (e.g. issue a rollback or kill the spid).

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand [MVP] Guest

  6. #5

    Default Re: How to execute an ADO query asynchronously?

    Yes (in the code of the first message I use Response.isClientConnected). But
    how can I use Response.isClientConnected if I do not execute the
    Connection.Execute call asynchronously?
    If I use Connection.Execute synchronously ASP request must wait until query
    terminates (and it can be long) and then I can use
    Response.isClientConnected to decide if return query result to client or
    not, but what I want to do is cancel query call, not cancel the return of
    data to the client.

    Thanks!

    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> escribió en el mensaje
    news:ut2v9Vp4DHA.3548@TK2MSFTNGP11.phx.gbl...
    > > In my case, querys always return data to the client.
    > > I want to execute them asynchronously to offer to the user the
    possibility
    > > of cancelling them.
    >
    > That's not what asynchronous is for. Checks to Response.isClientConnected
    > can allow you to cancel your query (e.g. issue a rollback or kill the
    spid).
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > [url]http://www.aspfaq.com/[/url]
    >
    >

    kibokochui Guest

  7. #6

    Default Re: How to execute an ADO query asynchronously?

    >Re: How to execute an ADO query asynchronously?
    [url]http://81.130.213.94/myforum/forum_posts.asp?TID=60&PN=1[/url]

    --
    Mike Collier BSc( Hons) Comp Sci
    FREE ado browser tool when you register online.
    [url]www.adoanywhere.com[/url]
    forum [url]http://www.adoanywhere.com/forum[/url]


    Mike Collier Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139