Operation is not allowed when the object is closed

M

Matt

Got this problem that killing me...what am i doing wrong with this old
dll. When i call the function from asp i get "Operation is not allowed
when object is closed"
any clue will be appriciated....

test .asp
<%
dim oObj
dim a
set oObj= server.CreateObject("MyDll.MyClass")

a = oObj.MyFunc()
Response.write a
%>

--------------declaration
Const Conn As String = "Provider=SQLOLEDB;Data
Source=MySource;Database=MyDataBase;UID=us1;PWD=us2"
Private m_objcontext As ObjectContext
Private Sql As String

-------------------

Public Function MyFunc() As Boolean

Dim oRs As ADODB.Recordset
On Error GoTo ErrorHandler:

vSql = "Select flag from flag_table"

Set oRs = New ADODB.Recordset

With oRs
.ActiveConnection = Conn
.CursorLocation = adUseServer
.CacheSize = 1
.Open Sql, , adOpenForwardOnly, adLockReadOnly
End With

If (Not oRs.EOF) And oRs.Fields("flag").Value = "Y" Then
MyFunc= True
Else
MyFunc= False
End If
oRs.Close
Set oRs = Nothing
m_objcontext.SetComplete
Exit Function
ErrorHandler:
If IsObject(oRs) Then
oRs.Close
Set oRs = Nothing
End If
m_objcontext.SetAbort
Err.Raise 21505, "blah", "blah- " & Err.Description
End Function
 
A

Anthony Jones

Public Function MyFunc() As Boolean

Dim oRs As ADODB.Recordset
On Error GoTo ErrorHandler:

vSql = "Select flag from flag_table"

Set oRs = New ADODB.Recordset

With oRs
.ActiveConnection = Conn
.CursorLocation = adUseServer
.CacheSize = 1
.Open Sql, , adOpenForwardOnly, adLockReadOnly
End With

If (Not oRs.EOF) And oRs.Fields("flag").Value = "Y" Then
MyFunc= True
Else
MyFunc= False
End If
oRs.Close
Set oRs = Nothing
m_objcontext.SetComplete
Exit Function
ErrorHandler:
If IsObject(oRs) Then
oRs.Close
Set oRs = Nothing
End If
m_objcontext.SetAbort
Err.Raise 21505, "blah", "blah- " & Err.Description
End Function

this line is causing the problem:-

If (Not oRs.EOF) And oRs.Fields("flag").Value = "Y" Then

Even though Not(EOF) may be false the expression Fields("flag").Value is
still evaluated resulting in an error (VB does not shortcut).

Use:-

If (Not oRs.EOF) Then
If oRs.Fields("flag").Value = "Y" Then

Anthony.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top