.NET Forum / ASP.NET / General / March 2008
Dataset being overwritten by multiple users?
|
|
Thread rating:  |
Chris - 12 Mar 2008 14:02 GMT I've got an aspnet page (vb) that runs a stored procedure, pipes it in a dataset, and binds to a gridview. The parameters for the stored procedure are some URL variables. My problem is when multiple ( 2 or more) people click on this link at the exact same time, the dataset seems to be getting overwritten. If person A clicks on their link, and person B clicks on theirs at the same time, person A is getting Person B's data, and vice versa. I'm almost positive this has something to do with multiple accessing the dataset at the same time. Is this the case? What's the workaround? TIA
Cowboy (Gregory A. Beamer) - 12 Mar 2008 14:22 GMT Most likely you are using a DataSet that looks something like this:
private static DataSet _dataSet;
//Routine to fill DataSet here //Something to return the DataSet
public static DataSet Data { get { ...} set { ... } }
If you program in VB, the word here is Shared.
Private Shared data As DataSet
'Routine to fill DataSet here 'Something to return the DataSet
Public Shared Property Data As DataSet Get ... End Get Set ... End Set End Property
Now, you may not realize you are doing this, as it may be hidden in someone else' library or a static/Shared class, etc.
I have been working with .NET since the early 1.0 betas and have never seen data cross like you are describing without something static/Shared. Most often people here that static/Shared members are more efficient, which is true in helper methods, but static/Shared means (quoting from Highlander) "There can be only one". :-)
 Signature Gregory A. Beamer MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box! *************************************************
> I've got an aspnet page (vb) that runs a stored procedure, pipes it in > a dataset, and binds to a gridview. The parameters for the stored [quoted text clipped - 5 lines] > something to do with multiple accessing the dataset at the same time. > Is this the case? What's the workaround? TIA Chris - 12 Mar 2008 14:40 GMT Yep, you're correct.
I'm doing a 'Public Shared blahblah as new DataSet', inside the class.
Partial Class test Inherits System.Web.UI.Page Public Shared ds As New DataSet
On Mar 12, 9:22 am, "Cowboy \(Gregory A. Beamer\)" <NoSpamMgbwo...@comcast.netNoSpamM> wrote:
> Most likely you are using a DataSet that looks something like this: > [quoted text clipped - 51 lines] > > something to do with multiple accessing the dataset at the same time. > > Is this the case? What's the workaround? TIA Cowboy (Gregory A. Beamer) - 12 Mar 2008 15:03 GMT Years ago, I consulted on a project where the user was actually changing as someone was doing work. The app was not allowed into the wild due to this FUBAR. I found this:
public class ApplicationSettings { private static ApplicationSettings _appSettings; private static User _websiteUser;
private ApplicationSettings() {}
public ApplicationSettings GetSingleton() { }
public ApplicationSettings GetSingleton(string userName) { } }
The second GetSingleton was set up to load a User when the person originally signed in.
The developer thought he was okay, since he was doing this:
Session["appSettings"] = ApplicationSettings.GetSingleton(userName);
Does not matter if you load this into Session or not, as it is a Singleton. That is one instance per entire application, not per session. He was constantly flipping from user's object to user's object. Furthermore, sometimes he was pulling like this:
appSettings = Session["appSettings"];
and sometimes like this:
appSettings = ApplicationSettings.GetSingleton();
I have also seen this:
private static SqlConnection;
public static SqlConnection GetSqlConnection() { }
This works fine on a low usage site, but becomes a bottleneck rather quickly when scaling.
 Signature Gregory A. Beamer MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box! ************************************************* Yep, you're correct.
I'm doing a 'Public Shared blahblah as new DataSet', inside the class.
Partial Class test Inherits System.Web.UI.Page Public Shared ds As New DataSet
On Mar 12, 9:22 am, "Cowboy \(Gregory A. Beamer\)" <NoSpamMgbwo...@comcast.netNoSpamM> wrote:
> Most likely you are using a DataSet that looks something like this: > [quoted text clipped - 58 lines] > > something to do with multiple accessing the dataset at the same time. > > Is this the case? What's the workaround? TIA Mark Rae [MVP] - 12 Mar 2008 15:09 GMT > Yep, you're correct. > > I'm doing a 'Public Shared blahblah as new DataSet', inside the class. And that's the problem... Shared variables (static in C#) are shared across the entire application in ASP.NET...
 Signature Mark Rae ASP.NET MVP http://www.markrae.net
Chris - 12 Mar 2008 15:23 GMT Makes sense now. Good ol' hindsight. So what other options do I have if I want to put this query in a dataset, but retain the information in the dataset after postbacks?
> > Yep, you're correct. > [quoted text clipped - 6 lines] > Mark Rae > ASP.NET MVPhttp://www.markrae.net Andrew Morton - 12 Mar 2008 18:02 GMT > Makes sense now. Good ol' hindsight. So what other options do I have > if I want to put this query in a dataset, but retain the information > in the dataset after postbacks? You can save data in the Session state (but I have a nagging suspicion that a dataset is not serializable, so you'd have to figure out a way to get the data into something that is, like an ArrayList).
Andrew
Mark Rae [MVP] - 12 Mar 2008 18:14 GMT > I have a nagging suspicion that a dataset is not serializable Yes it is - I do this all the time for smallish sets of data which (almost) never changes e.g. countries, currencies etc...
 Signature Mark Rae ASP.NET MVP http://www.markrae.net
Cowboy (Gregory A. Beamer) - 12 Mar 2008 18:57 GMT DataSets are XML, which is pretty much what serializable objects are serialized to. :-)
For the record, a DataSet IS serializable.
 Signature Gregory A. Beamer MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box! *************************************************
>> Makes sense now. Good ol' hindsight. So what other options do I have >> if I want to put this query in a dataset, but retain the information [quoted text clipped - 5 lines] > > Andrew Mark Rae [MVP] - 12 Mar 2008 18:08 GMT > > Yep, you're correct. > [quoted text clipped - 7 lines] > if I want to put this query in a dataset, but retain the information > in the dataset after postbacks? Remove the word 'Shared'
 Signature Mark Rae ASP.NET MVP http://www.markrae.net
Cowboy (Gregory A. Beamer) - 12 Mar 2008 18:56 GMT Cache. Viewstate. Session.
I am not going to recommend one over the others without knowing more about your application. You might also find that it is more efficient to simply query from the persisted store each time.
If the built in .NET items are not working for you, there are other cache solutions out there, like nCache from www.alachisoft.com. Not recommending that particular product, but it is one possiblity.
 Signature Gregory A. Beamer MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box! ************************************************* Makes sense now. Good ol' hindsight. So what other options do I have if I want to put this query in a dataset, but retain the information in the dataset after postbacks?
On Mar 12, 10:09 am, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "Chris" <coz1...@gmail.com> wrote in message > [quoted text clipped - 11 lines] > Mark Rae > ASP.NET MVPhttp://www.markrae.net
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|