How and Where to store the data
-
I'm new in ASP.net. I plan to develope a project based on ASP.net with C#. But I faced problem where how to store the data in ASP.net 2.0. For example, I had a few table in database -SQL server. Once the user search some information in database, it returned a list of record with content so that user can view them. And I planned to use object oriented way - create few classes such as order, order detail and invoice. Once the database returned the data to asp, it inserts data into those classes (order, order detail or invoice) and those classes can contain more that one record such as order1, order2, order 3 etc. But the problem is where should i store those classes that with data ? Should i store it in session or application? It is because once the user click to other asp.net pages, the classes that with data will lost. right? Sorry that asking this silly question. Any help with examples is appreciated. Danny
-
I'm new in ASP.net. I plan to develope a project based on ASP.net with C#. But I faced problem where how to store the data in ASP.net 2.0. For example, I had a few table in database -SQL server. Once the user search some information in database, it returned a list of record with content so that user can view them. And I planned to use object oriented way - create few classes such as order, order detail and invoice. Once the database returned the data to asp, it inserts data into those classes (order, order detail or invoice) and those classes can contain more that one record such as order1, order2, order 3 etc. But the problem is where should i store those classes that with data ? Should i store it in session or application? It is because once the user click to other asp.net pages, the classes that with data will lost. right? Sorry that asking this silly question. Any help with examples is appreciated. Danny
The web is stateless in it's basic form. As soon as you want to keep state, it will cost you, usually memory resources. Objects are normally not persisted from page to page, so the standard way of doing it is not to do it. Usually you just fetch them from the database again. If you want to persist the object, you can put them in session variables. Be carful about storing large objects in sesson variables, though, as the session objects live for a very long time. Objects in a web application usually lives mere milliseconds, so objects persisted in memory for minutes will be using relatively much memory resources. --- b { font-weight: normal; }
-
The web is stateless in it's basic form. As soon as you want to keep state, it will cost you, usually memory resources. Objects are normally not persisted from page to page, so the standard way of doing it is not to do it. Usually you just fetch them from the database again. If you want to persist the object, you can put them in session variables. Be carful about storing large objects in sesson variables, though, as the session objects live for a very long time. Objects in a web application usually lives mere milliseconds, so objects persisted in memory for minutes will be using relatively much memory resources. --- b { font-weight: normal; }
Ya. I know there is expensive to keep it on memory. But make always make a connection to database to fetch the data also expensive. Besides, users needs to wait for the procedure connect to database and obtain the data always. If I want to keep the data from database, session is the only way that I can use? Is there any other way to keep those data cross page to page?
-
Ya. I know there is expensive to keep it on memory. But make always make a connection to database to fetch the data also expensive. Besides, users needs to wait for the procedure connect to database and obtain the data always. If I want to keep the data from database, session is the only way that I can use? Is there any other way to keep those data cross page to page?
Pentellcc wrote:
But make always make a connection to database to fetch the data also expensive.
It's not expensive in the same way. Memory is a resource that has an absolute limit, while database calls are only limited by the execution time. Allocating too much memory causes the server to stop, while too many queries only makes it go slower.
Pentellcc wrote:
If I want to keep the data from database, session is the only way that I can use? Is there any other way to keep those data cross page to page?
Application variables, application cache, static variables... all those are shared by all users, though, so you need to separate the stored data using a unique key, and you need to use locking to make it thread safe. --- b { font-weight: normal; }