Solved

ADODB RecordCount, or OUTPUT parameter in stored procs: best practice

Posted on 2007-03-26
5
459 Views
Last Modified: 2013-12-25
keywords: ADODB CursorType CursorLocation RecordCount Output Parameter Stored Procedure  best practice
==========================================================

I need to get record counts on some recordsets that will be retrieved via ADODB command objects, using stored procedures. I'd like to know the wisest way to do this.

For a small (low traffic, few users) desktop client-server app using SQL Server 2005 through ODBC connection, in a small office LAN with a handful of workstations, is it faster/better to retrieve the ADO RecordCount by

A.) using an OUTPUT parameter in the stored proc that holds the COUNT
or
B.) use an appropriate CursorType, CursorLocation, and read the .RecordCount property from the recordset? (adOpenStatic and adUseServer?)

I'm sure there are times when both methods are wisest ("best practice"), but if I do not need to traverse the recordset more than once (forward), is there a performance penalty or something else that dictates which method to use?

Thanks!

Dennis
0
Comment
Question by:dtleahy
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 18795458
As a general principle, output parameter will be faster. In fact, you don't even have to create a recordset, simply execute the command and interrogate the output parameter. remember, you will not be returning the results set (less network traffic, CPU, memory across the board) simply the single parameter.
0
 
LVL 29

Assisted Solution

by:QPR
QPR earned 50 total points
ID: 18795466
If worried about performance you could ditch the recordset once retrieved and put the rows into an array using GetRows. Then you have the count and the ability to traverse back/forward as many times as you like.
0
 

Author Comment

by:dtleahy
ID: 18795873
Nightman and QPR, thanks for the rapid replies!

I do need the recordsets, I should have stated that. The recordcount is just to be used for programming logic:

If rs.RecordCount > 1 Then
   bla bla bla
End If

kind of thing.

You know, I never bothered to use GetRows until doing an ecommerce website with SQL Server on the backend. It is an excellent strategy, especially for web applications. This current (desktop) project was originally written using Access, and I'm porting it over to use a SQL Server backend. Quite honestly, I don't really have the time right now to change all the code necessary to access recordset records/fields as array items (which I also think are all typecast as variants, if I remember correctly),  but that may be good to keep in mind for an update to the code sometime later. For now, I just want to replace Access/Jet with SQL Server, add some stored procs, and use the existing code logic for recordsets.

Dennis
0
 
LVL 29

Accepted Solution

by:
Nightman earned 200 total points
ID: 18795895
You should just be able to use rs.RecordCount instead of having the overhead of performing a seperate count statement inside the stored procedure.
0
 

Author Comment

by:dtleahy
ID: 18796033
I'm awarding most of the points to Nightman, because I believe it's the correct answer. But, for those coming after me and searching for answers to performance problems and that need a count of records, especially in web applications, the GetRows strategy is wise, so QPR gets some points and is marked as an assist.

Thank you both!

Dennis
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Insert query into temp tables using Coldfusion 3 22
SQL Query assistance 16 27
Rename a column in the output 3 14
Merge two rows in SQL 4 17
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question