Discussion Locked

ASP Recordset.RecordCount = -1

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

This is killing me.
I'm using ASP 2.0 with SQL Server 7.0 and ADO 2.6
Here's the code I've written.

Set cn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
set cmd = Server.CreateObject("ADODB.Command")

cn.Open DSN, UserName, Password
cmd.ActiveConnection = cmd.CommandText = "{call stpAccessQCforPO(?)}"
cmdAccess.Parameters.Append cmdAccess.CreateParameter("@intCompanyID", adInteger, adParamInput,, CompanyID)
set rsAccess = cmdAccess.Execute

When I run this;
for cn, the connection string is valid, the state is open, and there are no errors.
for the cmd, the active connection is a valid connection string, the command text is correct, the parameter name, type & value are all correct

But the recordset's recordcount is -1. I can't figure out why. I have several other stored procedures just like this and they all work fine. When I execute the stored procedure in the query analyzer, 2 records are returned. Also, when I callthe recordset's activecommand propertie, an error is returned saying there was no value. I'm assuming that the command isn't executing into the recordset, but I'm really not sure what the problem is. Any help is greatly appreciated.

Thanks,
Drew

7 replies

by steved

Compared to your other stored procedures that do work, are you using the same connection string for this one? If not, is it the same type of connection string (i.e. DSN or DSN-less)?

I've found that the behavior of ADODB.command objects differs greatly when using a DSN-less connection compared to a DSN connection.

If that's not the difference, then I would want to see the exact code of one that does work in your environment in order to compare it with the one that doesn't.

Steve Diamond

by cheffero

Drew:
The problem is probably that ADO is using the default cursor type, ForwardOnly, which does not return a recordcount. Try explicitly setting the cursor type of the recordset to 'adOpenKeyset' *prior* to opening it. E.g.,

rs.CursorType = adOpenKeyset

where rs is a valid ADODB recordset. This should provide a valid recordcount property in rs. Caveat: with the keyset cursor, you will not see new records added after the opening of the recordset; also, you will not be able to access records deleted after the rs opening. Other data changes (updates) will be visible, however.

by kashifidrees

There is nothing wrong with ur code

the RecordCount Property only works for recordsets that support BookMarks.This property does not works with Server side Forward only cursors or Server side Dynamic cursors. Also plz do not use this property asthis property drains a lot of resources.

plz mail me at kashifidrees@yahoo.com and give me comments if u like my answer or not - or if u have any more problems

If u r using forward only cursor, then go to the end of the recordset (Last record) and then use RecordCount Property - it will work correctly.

by drewburlingame

This helped me determine that my recordset might be populating afterall, so I looked in other areas and found a simple mistake that made me think the recordset wasn't populating.

Thanks for the help.

This discussion is closed to new replies.