none
Problem with dataset and application variables RRS feed

  • Question

  •  

    Thanks in advance.

    My admin module is designed as follows:

     

     I will load xml file into a dataset and I will cache the data for 15 days. Later I will store dataset in the application variable.

     

    The data in the dataset is accessed in the live pages using this application variable. I actully followed this thinking that application variable will be available untill the application is closed in the server.

    To test I hosted my application on the server.

    I have loaded application variable with dataset data. And my intension is working fine ie I am able to access data in live pages. But the problem is data in the Applicaton variable got cleared after 20 or 25 minutes. But I dont want this to happen. Data in the app variable should not be cleared. If necessary I will override app variable with new data but i dont want app variable to get cleared.

    I have tested for many times, but the problem is same.

    The code what I use is as follows:

     

    DataSet ds;

     protected void TPGames_ServerClick(object sender, EventArgs e)
        {
            ds = (DataSet)Cache["CacheTPGames"];
            if (ds == null)
            {
                ds = new DataSet();
                ds.ReadXml(Server.MapPath("../RssFeed/Games.xml"));
                Application["playGames"] = ds;
                Cache.Insert("CacheTPGames", ds, null, DateTime.MaxValue, Cache.NoSlidingExpiration);
             }
            else
            {
                dt = DateTime.Now.Date;
                cachedTimeId.Value = Convert.ToString(dt.AddDays(15));
                ds = (DataSet)Cache["CacheTPGames"];
                Application["playGames"] = ds;
            }
        }

     

    I declared application variable in global.asax on application_start event  as follows:

    Application["playGames"] = "";

     

    Wednesday, June 4, 2008 9:24 AM

All replies

  • Their several ways to solved the problem.

    1. Build a windows service to visit the application periodically. (Ugly, huh?)

    2. Save it into a persist data storage, like database or file. Of course you need save the timeout with it. (Low performance, huh?)

    3. Save it into a persist data storage and the application variable. Get the application variable first. If it could be found, load it from the database, and set the application variable. (Great, huh?)

    Wednesday, June 4, 2008 12:49 PM
  • Thanks for replay.

      Can you make it clear further. I will be happy if you provide me with sample code.
    Thursday, June 5, 2008 4:51 AM
  • Here's a simple sample:

     

            ds = Cache["CacheTPGames"];

            if (ds == null)
            {
                ds = GetTPGamesFromDatabase();
                if(ds == null)
                {
                    ds = new DataSet();
                    ds.ReadXml(Server.MapPath("../RssFeed/Games.xml"));
                }
                Application["playGames"] = ds;
                Cache.Insert("CacheTPGames", ds, null, DateTime.MaxValue, Cache.NoSlidingExpiration);
                SetTPGamesToDatabase(ds);
            }
            else
            {
                dt = DateTime.Now.Date;
                cachedTimeId.Value = Convert.ToString(dt.AddDays(15));
                ds = (DataSet)Cache["CacheTPGames"];
                Application["playGames"] = ds;
            }

    Thursday, June 5, 2008 7:18 AM
  •  

    Thanks for your replay. Now what I have identified is Application_start event is fired twice. So the data that is present in the app variables has wiped out. I also tried to use cached data in the Application_start to repopulate app variables. Unfortunately  I was unable to find cached data when Application_start has fired for the second time. I also found reason for this i.e., application is recycling after particular time interval that was set by us.

     

    Now can any one tell me the way to access cached data in the Application_start event when it is fired for the second time. (sorry if u feel uncomfortable with my language.).

    Requirement is urgent. Thanks in advance for your replay.

    Friday, June 6, 2008 6:04 AM
  • please.. any one in this world.  Its urgent.

     

    Saturday, June 7, 2008 5:25 AM