Solved

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

Posted on 2007-03-26
5
463 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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Server connect issues 4 37
SQL Consolidate rows 3 24
SQL Server Error while building a sql query using concatenate statements 3 19
help converting varchar to date 14 25
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

680 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