Results 1 to 7 of 7

Thread: ADO GURU NEEDED

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Isle of Man
    Posts
    276
    I keep getting an error in my app: -

    Operation is not allowed in this context

    It seems to happen when I try to open a recordset that has caused an error in the past. When the error happens, my error handler jumps in: -
    Code:
    AddNewRecErr:
        MsgBox err.Number & ": " & err.Description
        
        For Each rec_err In NewRecSource.Cnn.Errors
            If TicketSaved = True Then
                message = rec_err.Number & ": " & err.Description & Chr$(13) & Chr$(13) & "Ticket Saved Okay"
            Else
                message = rec_err.Number & ": " & err.Description & Chr$(13) & Chr$(13) & "Ticket Not Saved"
            End If
            MsgBox message, vbExclamation, App.Title
        Next rec_err
        
        For Each rec_err In ImportDs.Cnn.Errors
            If TicketSaved = True Then
                message = rec_err.Number & ": " & err.Description & Chr$(13) & Chr$(13) & "Ticket Saved Okay"
            Else
                message = rec_err.Number & ": " & err.Description & Chr$(13) & Chr$(13) & "Ticket Not Saved"
            End If
            MsgBox message, vbExclamation, App.Title
        Next rec_err
        
        NewRecSource.Rs.Close
        ImportDs.Rs.Close
    as you can see, the last 2 lines close the recordsets that have been used. closing them here does not cause any errors, butmy data class tries to close the set beofore opening it using this code: -

    Code:
    Public Sub SetRs(ByVal sql As String)
        
        If ErrorOccurred = True Then
            Exit Sub
        End If
        If Rs.State = 1 Then
            Rs.Close
        End If
    
        Rs.Open sql, Cnn, adOpenKeyset, adLockOptimistic
    End Sub
    If i leave the lines to close the set out of my error handler, it throws the 'operation is not allowed...' error again when the class tries to close it, so i leave those 2 lines in. this doesnt really solve the problem, because when I try to open the set, i get the message again.

    the only thing to do is to quit the app (causing more of the same errors as the connctions are closed) and restart it. Is there a better way????????

    The I'm using a SQL 7 database accessed through an ADO data class. I have MDAC 2.5 installed on all machines, in case this is of any help.

  2. #2
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    London
    Posts
    290
    I`ll admit i only browsed your code briefly, cos i`m busy, but you can call the method .State.
    Ie.

    If cnDatabase.State <> adStateOpen Then blah blah

    (Thats a connection object, but it works on recordsets too).

    So check its open before you close it, and vice versa.

    Alex.

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Originally posted by Jimbob
    I keep getting an error in my app: -


    If i leave the lines to close the set out of my error handler, it throws the 'operation is not allowed...' error again when the class tries to close it, so i leave those 2 lines in. this doesnt really solve the problem, because when I try to open the set, i get the message again.

    the only thing to do is to quit the app (causing more of the same errors as the connctions are closed) and restart it. Is there a better way????????

    The I'm using a SQL 7 database accessed through an ADO data class. I have MDAC 2.5 installed on all machines, in case this is of any help.
    Are NewRecSource and ImportDs database objects? And how is the Sub SetRS aware of them?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Isle of Man
    Posts
    276
    They are both instances of a class. defined within the class are rs and cnn (Adodb.recodset and .connection)

    SetRs is a method of that class

  5. #5
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Is Rs "Public" (is AddNewRecErr allowed to manipulate the class variable directly)?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Isle of Man
    Posts
    276
    yes, the recodset is a public property, so AddNewRecErr: can manipulate it.

    i know i should really use public properties and let get and set, but the amount of code i would have to write, i just can't be bothered!!


  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Isle of Man
    Posts
    276
    Pallex,

    I've checked the state of the rs and the cnn, both of them are 1, which should mean open...

Posting Permissions

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



Click Here to Expand Forum to Full Width