Monday, February 21, 2011

Static dataset in ASP.NET

Will declaring a dataset as STATIC in ASP.net website help in persisting data across post backs?

I was looking at an application and somehow a static dataset was able to persist the data even if we closed the application and opened it again.

From stackoverflow
  • Yes, it can. static variables are stored in server memory. Note that they are shared among all users (like Application state) and it might require a locking mechanism to ensure thread safety.

    Note that it will be gone if the application ends.

  • yes, but try to use Application object like

    Application.Add("yourDS",Dataset);
    

    Note: When your application restart application object lose data.

  • I strongly recommend you to avoid using any global objects in ASP.NET application (of course there are exceptions, like Cache). You will always have to deal with concurrency while updating this DataSet and additionally, you'll make a lot of your modules dependent on single data structure.

0 comments:

Post a Comment