PDA

Click to See Complete Forum and Search --> : ADO GURU NEEDED


Jimbob
Aug 4th, 2000, 05:01 AM
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: -

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: -


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.

Pallex
Aug 4th, 2000, 06:07 AM
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.

JHausmann
Aug 4th, 2000, 01:51 PM
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?

Jimbob
Aug 5th, 2000, 07:33 AM
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

JHausmann
Aug 7th, 2000, 11:09 AM
Is Rs "Public" (is AddNewRecErr allowed to manipulate the class variable directly)?

Jimbob
Aug 7th, 2000, 11:15 AM
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!!

Jimbob
Aug 8th, 2000, 04:26 AM
Pallex,

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