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

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
 
B

bruce barker

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)
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top