RE: ViewState vs. Database



Hi,

From your description, you're wondering tradeoff between storeing database
records in ASP.NET page's viewstate and query them in every request,
correct?

Based on my understanding, if you're using Databound control(such as
Gridview, DataGrid) to display data queried from database, after you
perform databinding, the viewstate will automatically store those necessary
info for the Gridview/DataGrid to display each rows in sequential requests.
However, the database table based structure is not persisted
automatically. Therefore , I'm wondering what you want to do or what's the
reason that you may need to cache/store the entire database table (e.g.
datatable/dataset) into Viewstate?

For general consideration, I think you can consider the following factors:

1. ViewState is only used for store data which need to reuse between the
same page's multiple post. If you request the page(via HTTP GET) again, the
viewstate(stored in previous request) is no longer available. For data
that need to be persisted between multiple page or requests(not only
postback), I think Session State and Application Cache is better.

2. For impaction, since viewstate is persisted as an html hidden field in
page's html source, if the data you want to store is very large, it will
surely increase your page's response content size and that'll make the page
display or postback slowly for low bandwidth clients(for internet
scenaros). And if you cache large data in SessionState or Application
Cache, that will not impact response stream size, but if that is used
frequently, the server-side memory will have some pressure.

3. If the bottleneck is not at the web application and backend database
server(performing data accessing operations such as query data), I
recommend you query the data from database in every request where you need
to display the data. But if the data is large and really static or
unchangable, you can consider using Application Cache to cache them.

#Using the ASP.NET Application Cache to Make Your Applications Scream
http://www.developer.com/net/net/article.php/1477771

#ASP.NET Caching Overview
http://msdn.microsoft.com/en-us/library/ms178597.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
Thread-Topic: ViewState vs. Database
thread-index: AcjiL9LHoL7fpWJYTuakWT7C3nnrKw==
X-WBNR-Posting-Host: 207.46.19.168
From: =?Utf-8?B?TUNN?= <MCM@xxxxxxxxxxxxxxxx>
Subject: ViewState vs. Database
Date: Wed, 9 Jul 2008 18:54:00 -0700


I'm sure the answer to my question varies depending on the situation, but
I
am looking for a general "best practice".

If I have an asp.net application and I load certain data from a database,
should I use ViewState to store and reload the data, or should I load the
data from the database on each postback?

Assume for the sake of this question that I only care about performance, I
don't care about ease of programming.



.



Relevant Pages

  • RE: ViewState vs. Database
    ... records in ASP.NET page's viewstate and query them in every request, ... Using custom display controls. ... recommend you query the data from database in every request where you need ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.general)
  • [TOOL] ISR-Sqlget - Blind SQL Injection Tool
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Random uppercase request transform ... Database schemate download blacklist ... Cookie array support ...
    (Securiteam)
  • Re: datagrid paging and XML
    ... You would access your data source in the Page_Load event handler in a Non ... DataGrid data is stored in ViewState. ... small amounts of data on any given page request. ... > will the system access the database each time you ask the next page ... ...
    (microsoft.public.dotnet.framework.adonet)
  • ASP.NET __VIEWSTATE crypto validation prone to replay attacks
    ... ASP.NET's extremely popular __VIEWSTATE functionality provides an automatic, ... uniform method for storing current state of all webpage "controls" (including ... form fields, database views, etc), so that user-entered data automagically ... SHA1 validation, may send shivers down any infosec guy's or gal's spine, ...
    (Bugtraq)
  • Re: Disable Viewstate
    ... From your description, even if ViewState is disabled, you can still see ... We cannot disable control state. ... Microsoft Online Support ... nature are best handled working with a dedicated Microsoft Support Engineer ...
    (microsoft.public.dotnet.framework.aspnet)

Loading