Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am receiving the error "Operatio

Status
Not open for further replies.

grayghost144

Technical User
Aug 19, 2003
2
US
I am receiving the error
"Operation is not allowed when the object is closed. "
when running the below script. Not sure why.

I have verified the sql statement works using sqlserver 2000 query analyzer. I suspect the statement is erroring with no indication why and therefore the recordset is not open (I could be way off)

The error occurs in the line
If rs2.RecordCount > 0 Then

Any help would be appreciated.
======
Code:
<script language=VBScript RUNAT=Server>

    dim cn2
    dim RS2

    Set cn2=Server.CreateObject (&quot;ADODB.Connection&quot;)
    cn2.open &quot;File Name=C:\Inetpub\[URL unfurl="true"]wwwroot\HD\Scripts\ssidb.udl&quot;[/URL]

    Set rs2=Server.CreateObject (&quot;ADODB.Connection&quot;)
    rs2.open &quot;select * from profile&quot;,cn2,1,1

    If rs2.RecordCount > 0 Then
      rs2.close
      cn2.close
      set rs2=nothing
      set cn2=nothing
    end if
 
grayhost144

I'm not a whizz with ASP but where you have
Set rs2=Server.CreateObject (&quot;ADODB.Connection&quot;)
should be
Set rs2=Server.CreateObject (&quot;ADODB.Recordset&quot;)
to instantiate the Recordset Object. Your Connection is ok ie
Set cn2=Server.CreateObject (&quot;ADODB.Connection&quot;)
but if you try to run a query against a Recordset that isn't open it would probably say that the Object is Closed as it does in your case. If you replace Connection with Recordset as I've indicated above it should be ok.

Also

Where you have this If construct:-

If rs2.RecordCount > 0 Then
rs2.close
cn2.close
set rs2=nothing
set cn2=nothing
end if

You would normally close the Object then set it to nothing immediately afterward as below.
If rs2.RecordCount > 0 Then
rs2.close
set rs2=nothing
cn2.close
set cn2=nothing
end if

This wont have anything to do with the error but more a coding convention thing. Hope this solves your problem.

 
Thanks - My inexperience with vbscript shows.

I was looking right at the error and didn't see it. I kept looking at the open statement and missed seeing the createobject mistake.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top