Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 recordcount funnies

Author  Topic 

watchinthegame
Starting Member

2 Posts

Posted - 2007-08-15 : 01:21:38
Hi,
I have a problem that I am certain will turn out to be silly.

The code below returned a populated recordset when using SQL server (2000) on one server and returns a recordcount of -1 when used with another SQL server (also 2000).

As you can see the adOpenStatic = 3 and adLockOptimistic = 3 so it's not these (besides they worked fine on the first server)

Can anyone suggest options?

here is my asp code:

strConnection = "PROVIDER=SQLOLEDB;DATA SOURCE=111.111.111.111;UID=user_ID;PWD=Password;DATABASE=database"

Set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open strConnection

set rs = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT * FROM Table"
rs.Open sSQL, DBConn, 3, 3
Response.write rs.recordcount
rs.close
set rs = nothing

DBConn.Close
Set DBConn = Nothing

pootle_flump

1064 Posts

Posted - 2007-08-15 : 04:01:27
-1 means there are records but the client has not populated the recordset. Use rs.MoveLast to populate it and then count. Or you can set the cursor location to adUseClient. Unless you are going to use all the records then try to avoid populating the recordset with all records as this is innefficient if all you want to do is count them - get the server to count them and pass that value to the client.
Go to Top of Page

watchinthegame
Starting Member

2 Posts

Posted - 2007-08-15 : 21:27:15
Many thanks P_F,

Your advice is well appreciated. Strange that the code returned a populated recordset on one server but returns -1 on another server... same table, same data, same asp code... I may need to look into it further.

Thaks again :)
Go to Top of Page
   

- Advertisement -