Alternative to storing datatable in session in

mmalik15 used Ask the Experts™

I understand that storing datatable in session variable in is bad since it will use a lot of server's mememory.  What's are the possible alternatives? In case my page need to display about 50 records pulled from sql server database for say 50 concurrent users.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If it's cross page you definitely can't use viewstate. And to be honest for that amount of data, viewstate would be a terrible place to store data.

Ideally, storing anything large in session isn't a good idea because it uses server resources (ie memory), but if you plan for that and understand its limitations then it can be acceptable to use it. Just be aware of those downsides. I'm working on an app at the moment that stores lots of data (not as much as you) in the session; it's a low usage application so this won't cause any undue effects.

You could of course, us external session state, but there are downsides with that too. Essentially state management of large items is always a trade-off. Session is fast but uses resources, databse is slower but uses less resources.

Using the cache wouldn't work because ASP.NET can evict items from the cache if it needs the memory.

Refer for more details
Hi! You can read data from database on every page request (get or post), without any caching. I guess it should not make your page too slow (you can optimize db connection, using connection pooling).

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial