GeorgeS
Posts: 206
|
| Posted: 12/11/2004, 6:30 PM |
|
I get the error "ADODB.Recordset error '800a0e78' - Operation is not allowed when the object is closed" if I'm using the following Function from CCS Help file:
_______________________________________________
Function UserInfo_BeforeShow()
Dim SQL
Dim RecordSet
Dim UserId
' Read user_id from URL
UserId = CCGetFromGet("user_id", 0)
If UserID > 0 then
SQL = "SELECT * FROM employees WHERE emp_id="&UserId
' Open the recordset
Set RecordSet = DBConnection1.Execute(SQL)
If DBConnection1.Errors.Count = 0 Then
If NOT RecordSet.EOF then
UserName = CCGetValue(RecordSet, "emp_name")
WorkPhone = CCGetValue(RecordSet, "phone_work")
End if
' Close the recordset
RecordSet.Close
Set RecordSet = Nothing
Else
Print "SQL Execution Failed."
DBConnection1.Errors.Clear
End If
' Show a label value
UserInfo.Value = UserName & ", phone: "&WorkPhone
Else
UserInfo.Visible = False
End if
End Function
_______________________________________
If this function is modified like this - there is no error:
_____________________________________
Function UserInfo_BeforeShow()
Dim SQL
Dim CNN, RecordSet
Dim UserId
' Read user_id from URL
UserId = CCGetFromGet("user_id", 0)
If UserID > 0 then
SQL = "SELECT * FROM employees WHERE emp_id="&UserId
'open a New Connection
Set CNN=Server.CreateObject("ADODB.Connection")
CNN.open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("db/mydb.mdb")&";Persist Security Info=False")
'Open the recordset
Set RecordSet=Server.CreateObject("ADODB.Recordset")
RecordSet.Open SQL, CNN
If DBConnection1.Errors.Count = 0 Then
UserName = CCGetValue(RecordSet, "emp_name")
WorkPhone = CCGetValue(RecordSet, "phone_work")
End if
' Close the recordset and Connection
RecordSet.Close
Set RecordSet = Nothing
CNN.Close
Set CNN=Nothing
' Show a label value
UserInfo.Value = UserName & ", phone: "&WorkPhone
Else
UserInfo.Visible = False
End if
End Function
_____________________________________
Any ideas why in the first example RecordSet.Status was sometimes 0 and sometimes 1 when I was doing exactly the same thing?
Connection.Status was always 1 and UserID always had value - only the RecordSet.Status was randomly either 1 or 0
_________________
GeorgeS |
 |
 |
|