asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Is Paging with Recordsets the Best Method?
By 15 Seconds Discussion List
Rating: 3.4 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Bill Asks:

    When paging through a recordset, does the entirety of the query get called to the Web server each time and then only the appropriate records for the pagesize and absolute page are displayed? Or is it more efficient than that? Is there a better way to page through multiple recordsets?

    Trying to optimize things a bit and wanted to be clear on just what the recordset was doing.

    Paul Responds:

    Yes, ado isn't too bright about paging...you get the whole recordset. If you're using sql server you can do it with a temp table and only bring the records you need with each page.

    Try something like....

    CREATE PROCEDURE PageSet
    @PageSize integer,
    @PageNumber integer
    AS
    
    SET NOCOUNT ON
    CREATE TABLE #SearchResults(
    result_number integer identity(1,1),
    result_id integer)
    
    SELECT [the pk of the table you want to page]
    FROM ....
    WHERE....
    INSERT #SearchResults(result_id)
    
    DECLARE @StartRecord int, @EndRecord int
    SET @StartRecord = (((@PageNumber - 1) * @PageSize) + 1)
    SET @EndRecord = (@StartRecord + @PageSize - 1)
    
    SELECT SR.result_id...
    FROM #SearchResults SR JOIN [the table to page] 
    ON SR.result_id = [the table to page].[the table to page's pk]
    WHERE (SR.result_number >= @StartRecord) AND (SR.result_number <=
    @EndRecord)
    DROP TABLE #SearchResults
    

    Michael R. Adds:

    Easiest way: Re-Query the database each time, paging to the appropriate page.

    Client-Side way: pass the data to the client (getstring / split) and go through the client.

    Session way: Set the session timeout to a smaller 5 min or so, and register the ADO free-threaded component, (vs. the both threaded), This means ADO will only support free-threaded drivers (No Access). Then you can use a disconnected recordset object in a session safely. The main reason to not use ado is because the default is both-threaded, which is serialized in use. The reason it is both threaded is to support single-apartment threaded drivers (Jet/Access, and a few others), if the driver being used is free-threaded (SQL, Oracle, and others), using the free-threaded ado dll won't serialize when used in asp.

    David Suggests Something Else:

    You could also persist the data to XML and page that.

    Rob Shares His Thoughts:

    store a recordset object in the ASP Session and your doomed to fail.....kiss server scaleability (and your ass) goodbye!!!

    BUT if it is limited to an intRAnet, you might be able to get away with it.

    AND if you have your own custom session manager which is scaleable, you could easily persist the disconnected recordset to ADTG (or XML) and persist using that format within your session manager.

    here's some resources:
    http://www.aspfree.com/devlinks/search.asp?catid=123&file404=#Recordset_Paging

    Steve Likes Java:

    surprised no one mentioned this 4guys article.... well, that i saw anyway 8-)

    http://www.4guysfromrolla.com/webtech/050901-1.shtml

    Java client-side pagination, it is pretty slick!

    Ben Tries Paul's Solution:

    It works great, I have one question though. This method works well, until I start dealing w/ recordset of over 50,000 records, then it takes up to 5 seconds just to execute the query because it has to build the temp table each time. Is there a way to speed this up, or to fill the temp table just with the section of records I am working with? Has anyone tried to implement paging on the server side with large recordsets? Any help would be greatly appreciated.

    Paul:

    Possibly...firstly you could do SELECT TOP to always limit it to the maximum possible records (PageSize * PageNumber). You could also set up triggers on the table(s) to be paged to pre-emptively build an aggregate table with a consecutive identity (an index, which would speed it up even more) to page with instead of creating the temp table with every page request...

    Rob Goes with XML:

    If you want to get this crazy (which are very very excellent ideas), you could also consider caching (and refreshing that cache) to disk each set of X number of records in ADTG/XML format. If done in XML format, a simple XSL would transform to display properly...This recognize some serious performance improvements.

    Ken Runs Some Tests

    The stored procedure method doesn't seem to be scalable at all. The adOpenStatic/.AbsolutePage method does scale linearly, but it's very slow.

    Fastest, if you're using SQL Server, is .getRows(numRecs) where you pull only numRecs records into the VBScript array (rather than the whole recordset).

    eg .getRows(20) will give you a VBScript array with only 20 records in it.

    Results here: http://www.adOpenStatic.com/experiments/recordsetpaging.asp.

    15Secs Editor Offers:

    Also see this article on 15Seconds:

    Paging: Use ADO, getrows, or a Stored Procedure?
    http://www.15seconds.com/Issue/010308.htm

    This conversation string was taken from the 15Seconds ASP Listserv on 6/6/01. If you have an ASP-related question or would like to share some of your knowledge with others, you may join the list by clicking here.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    Proposion N2N
    Proposion N2N connects Microsoft .NET applications to Lotus Notes and Lotus Domino databases. This ADO.NET managed data provider allows you to perform blindingly fast queries and updates of Notes data from ASP.NET pages, .NET web services, Windows, or Mobile applications. An innovative SQL-like query language leverages the unique features of Notes and makes collaborative software accessible to relational database programmers.
    [Top]
    Other Articles
    Sep 15, 2005 - Building an Image Keyword System
    Unlike text-based file formats image files aren't made up of words, which makes searching for an image file by keyword difficult. Instead of being able to simply open the file to see what it contains, we're stuck looking at the text around it and other metadata to determine the image's meaning. In this article, Ziran Sun shows you how to build a simple database-based image keyword system that allows you to associate keywords with images and use these keywords to make finding images easier.
    [Read This Article]  [Top]
    Apr 7, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 2
    In the second part of of his article on using MySQL with ASP.NET, Ziran Sun covers how to add a new MySQL user to the database server, assign the user the appropriate permissions, connect to the database, and build a simple ASP.NET page to perform a query.
    [Read This Article]  [Top]
    Feb 10, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 1
    Back in the days of classic ASP, if you were building a database-driven web site, your choice was either to invest a lot of money to get a copy of Microsoft SQL Server (or some other enterprise-ready database) or invest a lot of time finding a way to deal with the performance and scalability limitations of Microsoft Access. Luckily these days there's another viable alternative: MySQL.
    [Read This Article]  [Top]
    Jan 27, 2005 - Moving a Database from SQL Server 7.0 to SQL Server 2000
    Moving or copying a SQL Server database from one machine to another requires a lot of preparation in order to ensure a smooth transfer. In this article, Dina Fleet Berry examines the different methods and highlights the different issues associated with each of them.
    [Read This Article]  [Top]
    Jan 6, 2005 - Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer
    There are many times when using SQL Server 2000 Query Analyzer to debug SQL statements is a better choice than debugging in Visual Studio .NET. In this article, Dina Fleet Berry explains why and walks you through the debugging process step-by step.
    [Read This Article]  [Top]
    Nov 24, 2004 - Persisting .NET Objects to SQL Server Using SQLXML and Serialization
    As a follow up to his article on retrieving objects from SQL Server using SQLXML and serialization, Gianluca Nuzzo discusses saving objects back to SQL Server using a schema definition file and updategrams.
    [Read This Article]  [Top]
    Sep 14, 2004 - Transaction Processing in ADO.NET 2.0
    One area that stands out when comparing ADO.NET 1.x to ADO.NET 2.0 is transaction processing. Bill Ryan shows just how easy transaction processing has become with the TransactionScope object in ADO.NET 2.0.
    [Read This Article]  [Top]
    Sep 8, 2004 - Custom Object Data Binding with .NET
    Developers often use brute force coding to marshal data between the GUI and application objects. In this article, Luther Stanton explains how to use .NET's out-of-the box data-binding functionality to make this job much easier.
    [Read This Article]  [Top]
    Sep 2, 2004 - Queue MSMQ Messages from SQL Server
    Learn how to create a console application to queue a message in Microsoft Message Queuing (MSMQ) and then use an extended stored procedure to call the console application from a SQL Server trigger.
    [Read This Article]  [Top]
    Aug 30, 2004 - Tuning Up ADO.NET Connection Pooling in ASP.NET Applications
    Connection pooling increases the performance of Web applications by reusing active database connections instead of creating a new connection with every request. This article shows how to monitor the connection pool, diagnose a potential problem, and apply the appropriate fix.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers