Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2004, 09:45 AM
Authorized User
 
Join Date: Nov 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Static DataSet

Hi, This is regarding an ASP.NET (C#) Web Application. I've written a common base class which does some common operations. And then there are several pages that inherits the funtionalities from this common base class.

In the base class, I've declared a static dataset. This dataset serves as an input to the datagrid in all the individual aspx pages. Each of these individual aspx pages has sorting, paging & searching functionalities. Because of the static nature of the dataset, even during a post back, the values in the dataset is retained, helping me in managing my sorting, paging & searching functionalities.

But when it comes to multiuser scenario (2 instances of browsers calling the same functionality of an aspx page), the static dataset is creating an issue. For e.g., I open 2 instances and look at a common page, say one.aspx. In browser 1, I search in the datagrid in one.aspx based on a particular criteria. In there I populate the static dataset with the records retrieved. In browser 2, I try to search the datagrid in the one.aspx for a different criteria. But my static dataset has the values of that of browser 1 ,and hence returns me inappropriate results.

The problem is, I can't do away without static, because there are many one.aspx's which is using the base class. Is there anyway in which I can retain a seperate instance of the static dataset for each of the one.aspx's or any method through which I can solve this multiuser issue.

Hope I was clear in my issue. Thanks for replies.

 
Old August 17th, 2004, 10:36 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

How is this dataset static? I'm not clear on how you are maintaining the dataset across page instances. I didn't think it was even possible using class structure. Are you maintaining it in the cache or in the Application scope collection?
 
Old August 18th, 2004, 12:41 AM
Authorized User
 
Join Date: Nov 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've declared the dataset in the base class as follows
Public static DataSet objDS = new DataSet()

So wherever I'm making an instance of the base class, I get to access the dataset as follows

BaseClass.objDS

 
Old August 18th, 2004, 06:05 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ok, that answers the access question, but how are you maintain the state of this dataset? Each page hit is a new instance of the page class (and the inherited base page class). This means that the dataset is new as well, so you must be persisting the dataset somehow. Are you loading it from something each time the page loads? Are you saving it to the cache and reloading it from there? I don't see from the code you have presented so far how it's at all possible that this dataset could be visible between page instances.
 
Old August 19th, 2004, 02:12 AM
Authorized User
 
Join Date: Nov 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In my one.aspx, I've the code as follows:
         public BaseClass bc = new BaseClass();
The above code is declared globally, so that it can be accessed across one.aspx

In my BaseClass, I've the code as follows:
         public static DataSet objDS=new DataSet();

In my one.aspx, I'll not get the reference to the DataSet if I use the object derived from the BaseClass. For instance,
         bc.ObjDS is not possible

But in my one.aspx, I can get the reference if I directly use the name of the class. For instance,
         BaseClass.objDS
Reason being, it's Public and importantly it's also Static. If it were not to be static, then I would not had access to it.

I've not used any Cache or Session to persist the state of the dataset that is being created. So as you said, everytime I'm calling the one.aspx, a new instance of objDS is created. But when I debug and see with 2 instances of browser open, the value of the objDS seems to be common for the 2 instances. Which is what is creating the issue! I was wondering how this could possibly happen, but the dataset's Static Scope is doing all this.

Let me take an example:
One.aspx Inherits BaseClass
.ASPX
(a) ComboBox
(b) DataGrid --> DataSource is BaseClass.objDS
.CS
BaseClass.objDS --> Populated from the database table for the item selected in ComboBox

Two.aspx Inherits BaseClass
.ASPX
(a) ComboBox
(b) DataGrid --> DataSource is BaseClass.objDS
.CS
BaseClass.objDS --> Populated from the database table for the item selected in ComboBox

Functionality Browser 1
(a) Select an item from Combobox. Say Country1
(b) Populate the BaseClass.objDS from the database table. Say all States belonging to Country1
(c) Bind the DataGrid

Functionality Browser 2
(a) Select an item from Combobox. Say Country2
(b) Populate the BaseClass.objDS from the database table. Say all States belonging to Country2
(c) Bind the DataGrid
(d) I sort on the StateColumn of DataGrid in descending order. RowFilter is Country2 from the combobox. The DataGrid is sorted in desc order

Now the BaseClass.objDS is filled with the results from Browser 2 for Country2. Datagrid is sorted in descending order.

Sorting function happens in the BaseClass. I've a routine called DataBind, which takes the DefaultView from the BaseClass.ObjDS and assigns to a new DataView object. I provide the sort expression to the Sort property of the View & then Bind the Datagrid.

Now I highlight Browser 1. The combobox shows Country1 & DataGrid is filled with the states belonging to Country1. I now sort the StateColumn in the datagrid.

I've not populated the BaseClass.objDS anywhere either through a database trip or using a Cache or using a Session. Reason, Static nature persists the contents across postbacks.

I placed a debug point in the DataBind function. When I watched the contents in the BaseClass.objDS, it contains the contents of Country2, but I'm currently in Browser 1 and the contents that I was expecting is of Country1. And hence the problem, while I finally Databind - I get wrong results. Infact I see a blank DataGrid, because the filter criteria is wrong for the available contents in the BaseClass.objDS.

I guess the reason is because the DataSet is Static, I still get to see the same DataSet across all browsers. Even though a new instance of the DataSet is created for each instance, the reference point is 1. That's my problem. I shouldn't have used a Static DataSet, because in MultiUser scenario - it fails. But I need a workaround. Kindly help. I hope I was comprehensive enough in explaining my problem. Please through some light. I've typed so much. :( :(

 
Old August 19th, 2004, 08:43 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm confused.
One.aspx Inherits BaseClass and there is a line in ur One.aspx
public BaseClass bc = new BaseClass();
How is it possible?!!!(what do u mean from inheriting?)


--------------------------------------------
Mehdi.:)
 
Old February 28th, 2008, 08:35 PM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think your problem is happening because you are declaring the dataset as static. When you declare an object as static it will persist through classes and that may be why you are getting data that crosses with multiple users.
After you fill your dataset, store the dataset using a session or viewstate:
Code:
 session["yourdataset"] = dataset;
then, when you need to get info from the dataset do this:
Code:
 dataset = (dataset)session["yourdataset"];
Then just use your dataset as normal. Remember to put it back in the session["dataset"] whenever you update or change something in your dataset. Hope this helps!

 
Old February 28th, 2008, 10:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by mp3rry
 Remember to put it back in the session["dataset"] whenever you update or change something in your dataset.

Technically, you don't need to do this. When you get a reference object from session, you're just getting a reference to it, so any changes to it will persist in the original object. Simple types (int, string, etc) do need to be updated back to the session.

-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 01:48 PM
Will static dataset affect the performance? hhkris4u ASP.NET 1.0 and 1.1 Professional 1 January 9th, 2007 12:05 PM
Converting a untyped dataset to a typed dataset daphnean Visual Studio 2005 0 July 13th, 2006 01:16 AM
Re: SQL Server dataset to ACCESS dataset dazzer ADO.NET 0 March 22nd, 2004 05:28 AM
static dataset ffranko99 VB.NET 2002/2003 Basics 0 August 1st, 2003 06:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.