Dataset being overwritten by multiple users?

C

Chris

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
 
C

Cowboy \(Gregory A. Beamer\)

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". :)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 
C

Chris

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
 
C

Cowboy \(Gregory A. Beamer\)

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.

--
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
 
M

Mark Rae [MVP]

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...
 
C

Chris

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?
 
A

Andrew Morton

Chris said:
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
 
M

Mark Rae [MVP]

And that's the problem... Shared variables (static in C#) are shared
across
the entire application in ASP.NET...

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?

Remove the word 'Shared'
 
M

Mark Rae [MVP]

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...
 
C

Cowboy \(Gregory A. Beamer\)

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.

--
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?
 
C

Cowboy \(Gregory A. Beamer\)

DataSets are XML, which is pretty much what serializable objects are
serialized to. :)

For the record, a DataSet IS serializable.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top