views:

173

answers:

3

What is the best way to save data in session variables in a classic web site?

I am maintaining a classic web site and want to be able to allow my users to demo all functionality of the site, this means allowing them to delete records.

The closet example I have seen so far are the demos of Telerik controls where they are saving the dataset in sessions on first load and allowing the user to manipulate the data.

How can I achieve the same in ASP with an MS Access backend?

A: 

You can store a connection or inclusive an object in a session variable as far you remember what kind of variable are you storing at the retrieving time. I had never stored a dataset in a session variable but I had stored a lot of arrays in session variables so you can use the ADO Getrows method to locate a complete dataset into a session variable.

backslash17
A: 

If you want to persist the state over multiple pages (e.g. to demo you complete application) then it's a bit tricky.

I would suggest copying the MDB file for each session and using the copied version. This would ensure that every session uses its own data.

  • create a version of your access db which will be used as a fresh template for each user
  • on session copy the template and name it after the users session ID
  • use the individual MDB

Note: Then only drawback I can see here is that you need to remove the unused MDB files as it can get a lot after sometime. You could do it with a scheduled task or even on session start before you create a new one.

I am not sure what you can use to check if it's used or not but check the files creation date or maybe the LDF file can help you as well (if it does not exist = unused).

Michal
A: 

How big is the Access database? If your database is small enough (relative to the server capacity, expected number of users, and so forth) then I like the idea of using a fresh copy of the database for each user that runs the demo.

With this approach, you simplify your possible code paths. Otherwise this "are we in demo mode or not?" logic will permeate a heck of a lot of your code.

I'd do it like this...

  1. When the user begins the demo, make a copy of the Access DB for that user to use. If your db is foo.mdb, copy it to /tempdb/foo_1234567890.mdb where 1234567890 is the user's session ID.

  2. Alter the user's connection string to point to the fresh database copy. From this point on, your app can operate like "normal" with no further modifications.

  3. Have a scheduled task that deletes all files in /tempdb with last-modified times more than __ hours in the past. If you don't have the ability to schedule tasks on the server (perhaps you're in a shared hosting environment, etc) then you could do this at the same time you do step #1.

John Booty