Operation is not allowed when the object is closed

Discussion in 'ASP General' started by Matt, Mar 3, 2006.

  1. Matt

    Matt Guest

    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
     
    Matt, Mar 3, 2006
    #1
    1. Advertising


  2. >
    > 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.
     
    Anthony Jones, Mar 4, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    2,134
    Kevin Spencer
    Aug 10, 2005
  2. Matthew Louden
    Replies:
    6
    Views:
    260
    Ken Schaefer
    Sep 28, 2003
  3. cliverama
    Replies:
    1
    Views:
    142
    Aaron Bertrand [MVP]
    Nov 5, 2003
  4. Guest
    Replies:
    1
    Views:
    240
    Ray Costanzo [MVP]
    Dec 20, 2004
  5. TC
    Replies:
    1
    Views:
    150
    madhouse
    Jan 12, 2005
Loading...

Share This Page