|
-
Aug 4th, 2000, 05:01 AM
#1
Thread Starter
Hyperactive Member
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.
-
Aug 4th, 2000, 06:07 AM
#2
Hyperactive Member
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.
-
Aug 4th, 2000, 01:51 PM
#3
Frenzied Member
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?
-
Aug 5th, 2000, 07:33 AM
#4
Thread Starter
Hyperactive Member
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
-
Aug 7th, 2000, 11:09 AM
#5
Frenzied Member
Is Rs "Public" (is AddNewRecErr allowed to manipulate the class variable directly)?
-
Aug 7th, 2000, 11:15 AM
#6
Thread Starter
Hyperactive Member
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!!
-
Aug 8th, 2000, 04:26 AM
#7
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|