Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2003
    Posts
    114

    Unanswered: Operation not allowed in this context

    This error message is showing up when I execute the following code (called in a function):

    Set rs = New ADODB.Recordset
    rs.Open "SELECT RacePl FROM IndResults, PartData WHERE RaceID = " & lRaceID & " AND IndResults.PartID = PartData.PartID ORDER BY EventPl", conn, adOpenKeyset, adLockOptimistic
    With rs
    For j = 0 To .RecordCount - 1
    rs(0).Value = j + 1
    If j < .RecordCount - 1 Then .MoveNext
    Next j
    .Close
    End With
    Set rs = Nothing

    Any idea what causes this to fire?

  2. #2
    Join Date
    Jan 2003
    Location
    Midwest
    Posts
    138
    what line is giving the error?
    Code:
    Set rs = New ADODB.Recordset
    rs.Open "SELECT RacePl FROM IndResults, PartData WHERE RaceID = " & lRaceID & " AND IndResults.PartID = PartData.PartID ORDER BY EventPl", conn, adOpenKeyset, adLockOptimistic
    For j = 0 To rs.RecordCount - 1
       rs(0).Value = j + 1
       If j < rs.RecordCount - 1 Then rs.MoveNext
    Next j
    rs.Close
    Set rs = Nothing

  3. #3
    Join Date
    Apr 2003
    Posts
    114

    The error is coming from...

    ...rs.Close.

  4. #4
    Join Date
    May 2003
    Posts
    12

    Re: Operation not allowed in this context

    I have no idea. But try this one:

    Code:
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open "SELECT RacePl FROM IndResults, PartData WHERE RaceID = " & lRaceID & " AND IndResults.PartID = PartData.PartID ORDER BY EventPl", conn, adOpenKeyset, adLockOptimistic
    
    For j = 0 To rs.RecordCount - 1
        rs(0).Value = j + 1
        If j < rs.RecordCount - 1 Then rs.MoveNext
    Next j
    rs.Close
    Set rs = Nothing

  5. #5
    Join Date
    Apr 2003
    Posts
    114

    I will give that a try but...

    ...what I have noticed is that if I comment out the rs.Close it runs just fine. That's not to say that it is ok to not close out your recordsets but, since I am new to ADO (always worked in DAO before) I am a little uncertain as to when that is/isn't necessary.

    Any ideas on that?

  6. #6
    Join Date
    May 2003
    Posts
    12

    Re: I will give that a try but...

    I suggest that you close your connection to the database and set the recordset to nothig:

    Code:
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open "SELECT RacePl FROM IndResults, PartData WHERE RaceID = " & lRaceID & _
        " AND IndResults.PartID = PartData.PartID ORDER BY EventPl", conn, adOpenKeyset, adLockOptimistic
    
    For j = 0 To rs.RecordCount - 1
        rs(0).Value = j + 1
        If j < rs.RecordCount - 1 Then rs.MoveNext
    Next j
    conn.Close 'Close the connection
    Set conn = Nothing
    Set rs = Nothing

  7. #7
    Join Date
    Apr 2003
    Posts
    114

    I usually keep the connnection

    open due to the frequent requests for data in my app. But I usually close the recordsets immediately. Comment please!

  8. #8
    Join Date
    May 2003
    Posts
    12

    Re: I usually keep the connnection

    Originally posted by Bobba Buoy
    open due to the frequent requests for data in my app. But I usually close the recordsets immediately. Comment please!
    What should I comment?

  9. #9
    Join Date
    Apr 2003
    Posts
    114
    You suggested that closing the connection was probably a good idea. I am noting that I usually leave the connection open during the life of the application since it is usually pretty active. I was wondering how bad of an idea you thought that was.

  10. #10
    Join Date
    May 2003
    Posts
    12
    Originally posted by Bobba Buoy
    You suggested that closing the connection was probably a good idea. I am noting that I usually leave the connection open during the life of the application since it is usually pretty active. I was wondering how bad of an idea you thought that was.
    If your application is used by many users at same time, it's a good idea to close the database connection. One open connection takes several kilobytes in memory.

Posting Permissions

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