473,563 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asp.Net session vs. Database Queries.

DNB
I did post this message in C# group also...

I would like to know what you guys think is the best way to access data:
Asp.Net session vs. Database Queries.

In our application we are using asp.net tree view to display hierarchical
data and when user clicks on particular node it brings up totally different
page with all the asp.net controls dynamically generated.
Example:
Tree view Control is as follow:
Student1
Student2
Student3
Student4
.......
......
.....
.....
Student 75

Now I have 2 options:
1) Now when user click on any node (i.e. Node Student2) another page will be
displayed and all the data related to that will be accesses from SQL server
using SQL Queries

2) OR Should all the data be accessed initially loaded into Session
Variable before building Tree View and when user access Node Student 2, just
get it from Session Variable.

Thanks
DNB
Nov 29 '07 #1
3 1582
If the dataset is small and unchanging you could store it in the
Application, or in some static (shared in VB.net) class properties. If the
dataset is large and/or frequently updated you're better getting it from the
database.
"DNB" <ii@ii.comwro te in message
news:Of******** ******@TK2MSFTN GP06.phx.gbl...
>I did post this message in C# group also...

I would like to know what you guys think is the best way to access data:
Asp.Net session vs. Database Queries.

In our application we are using asp.net tree view to display hierarchical
data and when user clicks on particular node it brings up totally
different
page with all the asp.net controls dynamically generated.
Example:
Tree view Control is as follow:
Student1
Student2
Student3
Student4
......
.....
....
....
Student 75

Now I have 2 options:
1) Now when user click on any node (i.e. Node Student2) another page will
be
displayed and all the data related to that will be accesses from SQL
server
using SQL Queries

2) OR Should all the data be accessed initially loaded into Session
Variable before building Tree View and when user access Node Student 2,
just
get it from Session Variable.

Thanks
DNB


Nov 29 '07 #2
Make your life easier, go ahead and load from the DB every time.

Unless you expect users to frequently click every node in the tree in rapid
succession, in which case you might want to reconsider your UI design
anyway.
"DNB" <ii@ii.comwro te in message
news:Of******** ******@TK2MSFTN GP06.phx.gbl...
>I did post this message in C# group also...

I would like to know what you guys think is the best way to access data:
Asp.Net session vs. Database Queries.

In our application we are using asp.net tree view to display hierarchical
data and when user clicks on particular node it brings up totally
different
page with all the asp.net controls dynamically generated.
Example:
Tree view Control is as follow:
Student1
Student2
Student3
Student4
......
.....
....
....
Student 75

Now I have 2 options:
1) Now when user click on any node (i.e. Node Student2) another page will
be
displayed and all the data related to that will be accesses from SQL
server
using SQL Queries

2) OR Should all the data be accessed initially loaded into Session
Variable before building Tree View and when user access Node Student 2,
just
get it from Session Variable.

Thanks
DNB

Nov 29 '07 #3
In general, I like to persist data in a database until it is going to be
used. You can prefetch some data, but loading a lot of data into session (or
cache) is not generally the first choice, as most of it will never be used.

In this case, I would NEVER use Session. Caching might be an option,
depending on the nature of the application.

Example: Seventy five students. Prefetch all data about the students and
cache (In this case, better than session). User clicks a single student. You
now have seventy four student's data loaded in session (ie, in memory) for
the length of the session, even though only one was used.

Here is why caching is preferred over session. You cache once across all
sessions, so the same data is available to all people using the particular
page. The cache can be set to update occasionally or, in custom situations,
based on events (very easy if using SQL 2005, 2008 -- requires polling in
2000). If 100 people are using this app at the same time, you have saved 99%
of the memory used to cache over loading in each session.

Here is why caching is not necessarily wise in this case: The more students,
the more information you are caching. And, this is likely to be information
you can just as easily query as needed (caching the query may or may not be
wise, depending on how many times the same person will access the same
record). You can also set cache to expire independently of session timeout.
If the information can be pulled as needed, with perhaps a temporary cache,
I would head this direction.

Now to your options
1) Now when user click on any node (i.e. Node Student2) another page will
be
displayed and all the data related to that will be accesses from SQL
server
using SQL Queries
This can be another page or another control on the same page. GridView and
DetailsView work very nicely together to make the application flow. Throw in
an AJAX UpdatePanel and you can even have the information flow in without a
full server round trip.
2) OR Should all the data be accessed initially loaded into Session
Variable before building Tree View and when user access Node Student 2,
just
get it from Session Variable.
Very rarely do I try to prefetch, much less into session

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************** *************** *************** ****
| Think outside the box!
|
*************** *************** *************** ****
Nov 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5689
by: dr. zoidberg | last post by:
Hello, I'm trying to create login system. I need some advices. Should I put Username and Password in session, and then check database for correct combination on every page, or should I just put userid in session, and then create queries. My sessions looks like this: uid|s:5:"admin";pwd|s:5:"test";
5
9603
by: Timin Uram | last post by:
Hey! Is there some sort of limit on how much one could store in a session as far as amount of data? Is it advisable to store a LOT of data in the session when a user logs in to save queries to the dbase while the user is browsing the site? Does this depend somehow on how many sessions are going on at once? Any input would be...
14
2586
by: mjkahn | last post by:
I've read (and read!) that you shouldn't store objects in Session variables. I've read these reasons: - The object takes up memory that may not be freed until the session times out. Better to create the object only when you actually use it. - Causes poor performance because the thread that created the object has to service all requests...
2
1624
by: eselk | last post by:
I'm new to ASP. If I store information in these handy "session variables" am I going to run into many limitations that I wouldn't have it I added a database record for each session instead? For example, if I use session variables, can I have an admin utility that lets me see a list and/or count of all open sessions? Or would I be able to...
9
1795
by: Mikel Astiz | last post by:
Hi, I am looking for a simple way to detect session ends so I can update a session table. I am new to PHP and don't understand how such event can be handled, since there seems not to be a corresponding overridable function. I've found 'register_shutdown_function', but apparently it detects connection breaks while the page is being loaded...
3
3052
by: Martin | last post by:
Hi all As my posting title suggests I'm having problems using InProc Session state in my ASP .NET app. I wrote a site for a friend which uses ADO .NET to keep track of a simple customer/purchases database. A user creates an account and a database entry is added to a customer table. Once a user successfully logs in with a valid...
4
2192
by: John Allberg | last post by:
Hi! We have a problem which is correlated to web farms and session handling and are thinking of what solution to choose. Our setup is with a web farm, one ldap server and a database cluster. The web farm is doing searches which are quite performance expensive against the ldap server, taking up to 10 or 15 seconds. The searches are...
14
2239
by: Rick | last post by:
We are in the process of testing a large web project that I converted from VS 2003 to VS 2005. Everything seems to be working except for a few minor things. But the main issue I have is this, I have about 5 or 6 developers testing this web site in a staging environment on a Microsoft 2003 Server box. We have a base page that gets called on...
6
2434
by: DNB | last post by:
I would like to know what you guys think is the best way to access data: Asp.Net session vs. Database Queries. In our application we are using asp.net tree view to display hierarchical data and when user clicks on particular node it brings up totally different page with all the asp.net controls dynamically generated. Example: Tree...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.