mehul9595
mehul9595

Reputation: 1955

Storing DataSet in ViewState or Session State

Currently I am storing the DataSet in a ViewState but, this may have an impact on the performance of the page.

Can you suggest me whether I can use Session or ViewState or any alternative by which it doesn't impact the performance?

Upvotes: 4

Views: 6835

Answers (4)

Sebastian Siek
Sebastian Siek

Reputation: 2075

Why do you need to store the whole dataset? If you have to, then do it in session. If your session is "inproc" the dataset object will be stored in memory (you save some performance because there will be no serialization).

If I was you, I would analyze the code and try not to store the whole dataset in neither session, not viewstate - there must be a way to optimize your code.

Upvotes: 3

William Proulx
William Proulx

Reputation: 65

If you want to store the whole dataSet there is always the Caching method wich will allow you to store huge variable with good performance. Here an example of how you can store a variable into Cache.

Cache["CacheItem1"] = "Cached Item 1";

And this how to retrive the variable after:

string cachedString;
cachedString = (string)Cache["CacheItem"];

Upvotes: 2

Ravi Gadag
Ravi Gadag

Reputation: 15851

as i think storing in session will may help you, but you need to think follwing points

  1. How many Users are Using Your application ?
  2. How much the dataset take size? if it is more , then dont store it in session.

I suggest you look on your requirement, if possible, you can store on cache, but it is application level. as Session Each User has its own session .

you can check the follwing links

  1. Session V/s Viewstate

Upvotes: 1

Umair
Umair

Reputation: 3243

Storing a dataset in viewstate or session is ill-advised, but out of the two, storing it in session is definitely better than viewstate. Since then the serialization/de-serialization is handled at the server. Rather than sending the serialized data to the client as well.

Upvotes: 1

Related Questions