session variables - how to handle parallel access by the same user tothe same page

  • Thread starter Thread starter Stephan Steiner
  • Start date Start date
S

Stephan Steiner

Hi

Here's the scenario I need to deal with:

I have an aspx page which allows creating and modifying data. There
are multiple GridViews allowing insert/update/deletes and various
other fields - in the end all ends up in an SQL Server DB. The
GridViews contains data that is tied to the primary key for a record
belonging to the page - so in the create case, I only get that key
once all the data has been filled out... but the gridviews need to be
filled prior to saving - so I implemented my own objectdatasource as
temporary storage and using the singleton approach (as otherwise,
whenver the grid is databound it shows no data as the objectdatasource
has been reinitialized).
In edit mode, upon initialization, the objectdatasource reads the data
from my SQL db.. then everything is in memory again until the user
saves the data.

All that works fine - but there's one problem when people are not
working in a linear fashion.

Suppose the user opens up record A. After loading, the
objectdatasource contains the data that depends on A. Then the user
opens up a new tab and opens up record. Now, the objectdatasource
contains the data that depends on B. Now he returns to the first tab
and saves.. .and he ends up with data that belongs to B.

I figure there are multiple approaches, but I wonder if there's
something more efficient.

For starters, I could add (and I did as a test) add the primary key
for the records to the data read from the database and stored in the
objectdatasource. That way, after the user has opened the second tab
and loaded B, the data source would contain the records for both A and
B.. and upon saving, only records that depend on A will be saved /
modified / deleted.

The only problem with that is if the user tries to create two records
concurrently.. the record key will be null so records from both tabs
will be mixed upon saving (and then I update all records in the
objectdatasource with the actual key from the DB so the second tab
will have no data left). I figure I could work around that problem by
assigning a random virtual key.. but I'd have to redo quite a bit of
the GUI because it is mean to work with null keys (it's an easy way to
identify that you're creating a new record) - plus, the length of the
key is limited, so there's a chance of random key collision.
Alternatively, add a "truly" random key like a guid as hidden field to
the page when it's first loaded, and add that to the objectdatasource.
that way, the null key won't bother anymore, but it's even more work.

Though I cannot help but think that this is a bit too complex - so
what are you guys using for this scenario? Is there something built-in
that could be leveraged?

Regards
Stephan
 
the simplest approach is to store the datasets in a dictionary. use a
transaction key to get the correct dataset. store this key in a hidden
field (or viewstate which is a hidden field).

be sure delete entries when done to save memory. a better idea would be
to also serialize the dataset to a blob in a sqltable, and fetch when
needed (or use sql sessions)

-- bruce (sqlwork.com)
 
Back
Top