469,336 Members | 6,062 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Operation is not allowed when the object is closed

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=us 2"
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

Mar 3 '06 #1
1 3752

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.

Mar 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by James Baker | last post: by
8 posts views Thread by Jim in Arizona | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.