Skip to content
Advertisement

operation not allowed when the object is closed when running more advanced query

When I try to run a more advanced SQL query on an ASP page I get this error:

operation not allowed when the object is closed

When I run this code it’s working:

But when I run this code (and this code is working if I run it in Microsoft SQL Server Management Studio), I get the error…

This is a better overview of the query:

Do I need to run the query on another way or what is wrong with this code?

Advertisement

Answer

This is a common problem caused by row counts being interpreted as output from a Stored Procedure when using ADODB with SQL Server.

To avoid this remember to set

in your Stored Procedure this will stop ADODB returning a closed recordset, or if for whatever reason you don’t want to do this (not sure why as you can always use @@ROWCOUNT to pass the row count back), you can use

which returns the next ADODB.Recordset if ADODB has detected one being returned by the Stored Procedure (might be best to check rs.State <> adStateClosed when dealing with multiple ADODB.Recordset objects).

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement