Session variable vs. Stored Proc

A

Andy G

I have a registration page that captures 75% of the users data. After they
enter that info they are redirected to one of two pages depending on how
they answered a question on the registation page. My question is would it
be better to store all of the fields(15 or so) from the first page in
session variables and reference them from the next page and run ONE stored
procedure OR would it be better to run a stored procedure the first page and
then run an update procedure on the next page with the rest of the fields?
So it would be 15 session variables with 1 stored procedure or 1 stored
procedure with 1 update stored procedure?

Thanks
 
B

Ben Strackany

You could also use one ASPX page for the whole process, store the
information from page one in hidden form fields, & then submit everything at
the end using one stored procedure.

Otherwise, probably still better to store in session & run one stored proc
at the end. Otherwise if your users bail out halfway through then you're
left with half-data in the database. Also, the one-proc approach will
probably perform better.

Only reasons you might want to do two procs is if a) you want to "remember"
the user's answers from the first page if they leave halfway through & come
back later, or b) you have so many users that storing that data in the
session object is causing the web server to run out of memory, or c) you
have environmental factors that cause users to lose their session
information from time to time (e.g. non-sticky load balancing, unstable
server, app pools recycyle frequently, etc.).
 
K

Karl Seguin

The answer ought to be answered by the desired persistance of your data.

If a user fills the first page but not the 2nd, should the data be
persisted? (ie, if the user was to come back, should he/she have to fill in
the first page again, or just the 2nd).

I would do 1 update (after both pages) if the two pages together are a
single transaction (either fill both or none). I would do 2 updates only if
it was imperitive that the first page data was saved regardless of what
happened to the 2nd page - unless this was a well defined requirement, I
would likely fall back to a single update.

Also note, that there are alternatives to using sesssions to persist the
data from one page to another. For example, Sever.Transfer can be made to
preserve state without requiring sessions (not that I have anything against
sessions, but just wanted to point out to alternatives).

Karl
 
H

Hans Kesting

Andy said:
I have a registration page that captures 75% of the users data.
After they enter that info they are redirected to one of two pages
depending on how they answered a question on the registation page.
My question is would it be better to store all of the fields(15 or
so) from the first page in session variables and reference them from
the next page and run ONE stored procedure OR would it be better to
run a stored procedure the first page and then run an update
procedure on the next page with the rest of the fields? So it would
be 15 session variables with 1 stored procedure or 1 stored procedure
with 1 update stored procedure?

Thanks

Just a note: if you are going for the session-variable approach, you don't need
to store the 15 values in 15 separate session variables: you can build a class
to hold those 15 values and store that class as a single session variable.

Hans Kesting
 
H

Hans Kesting

Andy said:
Hans that is a good idea. Where would you say I could declare that
class?

Anywhere you like really, as long as you can access it from your web project.
Maybe some library project in the same solution.
Don't forget to add a (project-)reference to that library project in the webproject!

Hans Kesting
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top