ADODB open recordset fails / "Operation is not allowed when object is closed" ADODB open recordset fails / "Operation is not allowed when object is closed" sql-server sql-server

ADODB open recordset fails / "Operation is not allowed when object is closed"


Ran into this error as well (in my case I am using a Stored Procedure to retrieve some information). I had made some changes which caused the execution to malfunction.

The error disappeared when I put SET NOCOUNT ON as the first statement of the Stored Procedure.


You do not need to SELECT the server side function, just provide its name ("[tra-CAE400-1].dbo.D100601RVDATABearingAllow") in the .CommandText property.Also you should set the .CommandType property to "stored-procedure" (property reference on w3schools.com).

Then adodb will know that you are talking about calling a function, and not trying to send a plain sql-command.

Chances are that it will then allow you to define the parameters on the command object.But the parameters you define on the command object should correspond exactly (in name and type) to the ones that are defined as the arguments of the function in the sql server.

An example from microsoft.com on using the command-object with a stored procedure

ADO Reference on microsoft.com


Another possible cause of this is debug statements. I just spent far too long trying to work out why this wouldn't work for me, the Proc on the database worked fine, the data it was supposed to insert was inserted, the VBA code worked fine, but there was nothing in the recordset.Final solution was to go through the procs that had been built and remove the PRINT statements.To test if this is the problem, run your proc on SQL Server manually, then look at the messages tab of the results, if there's anything there other than "Command(s) completed successfully." you need to eliminate those messages. "SET NOCOUNT ON" will get rid of the row count messages, but there may be others.

I'm assuming that after 5 years the OP has solved this particular problem, so this is just for anyone like me that finds this while searching for the same problem.