Search code examples
asp-classicvbscriptadodb

Classic ASP Error: Operation is not allowed when the object is closed


I have cruised and implemented code from some of the other responses to this question, but I'm still having no luck. I am still getting the error.

    If ((bReport And bIsDate And CheckPermissions("lotsales")) Or Request.QueryString("report")) Then
    OpenDB
    Dim oRs, sSQL, sSQL2, iCancellations, iSales, sDate, sInitDate, sEndDate, iPhaseID, iPhaseNumber, rowCount

    sInitDate = Request("startDate")
    sEndDate = Request("endDate")
    sSQL = "sp_get_lot_sales_test '" & sInitDate & "', '" & sEndDate & "', " & sPhase & ", '" & sReportView & "'"

    'response.write vbNewLine & "<!-- sql: " & sSQL & "-->" & vbNewLine
    'response.write sSQL
    'response.Flush
    Set oRs = ExecuteCommand(sSQL,1) 
End If

And then here is where the error occurs -

If (oRs.EOF) Then <-- fails here
       Response.Write("<TR><TD ALIGN=""center"">There is no data to report on!</TD></TR>")
    Else
        Do While Not oRs.EOF

As a last resort I am going to go back to the stored procedure and deconstruct it to make sure all is well there. Does anyone have any insight as to why I might be getting the error? I am not issuing a close anywhere.

Here is the ExecuteCommand function -

Function ExecuteCommand(s,i)
    On Error Resume Next
    Set ExecuteCommand = oDBc.Execute(s, , i)
End Function

Solution

  • You need a connection object.

    set conn = server.CreateObject("adodb.connection")
    set oRs = conn.execute(sSql)