class -session variable

G

Guest

Hi,
I want to do things this way:

I have a bunch of stuff that I want to keep track of while a user is
connected to the site. Maybe 50 little peices of information.

So I know I can make 50 session variables , or an store an array in a
session variable, but what I wanna do is store it all in a class
so I can use property get and property let.

I want to store this class in a session variable so I don't lose my info
everytime the page is changed.

Good Idea or not??
 
A

Aaron Bertrand - MVP

Why don't you store the info in a database, and all you have to store in the
session is the primary key...
 
T

Tammy B.

You would still have to store the class instance in a session variable .
That';s what I wanna do. I am just asking is it possible. I guess it must
be thanks. So I'll do it.
Your users can still whiz around your site if you just get it from the DB
each page.

I don't wanna do that, I've done that for years. gotta be a better way

thanks
 
A

Aaron Bertrand - MVP

You would still have to store the class instance in a session variable .
Your users can still whiz around your site if you just get it from the DB
each page.

And I contend that using the DB would almost surely be more efficient, given
correct indexing and cleanup of obsolete data...
 
T

Tammy B.

good to know.
And I contend that using the DB would almost surely be more efficient, given
correct indexing and cleanup of obsolete data...

Ok what I am doing is close to a shopping basket.

Here's an example. Basically, if the session variable exists then use it,
otherwise go look it up.
Saves a trip to the database if not needed.
But it would be simpler to just have Current_vendor_name be a property of a
class.

Response.write getCurrent_VENDOR_NAME()

function getCurrent_VENDOR_NAME
if session("Current_VENDOR_NAME")="" then 'if session variable does not
exist then go look it up
sql = " Select VENDOR_NAME from user_settings where username='" &
getusername() & "'"
getrecordset(sql)
session("Current_VENDOR_NAME") =rs(0)
else
'if session variable does exist then do nothing
end if
getCurrent_VENDOR_NAME= session("Current_VENDOR_NAME") 'return the
session variable
end function
 
B

Bob Barrows

I would certainly consider caching this data locally on the server rather
than going back and forth to the database for it. I don't know if you'll be
able to store a class in Session or not, so I won't comment on that.

Have you considered using an xml document? You could save it to an xml file
instead of using Session, which has some drawbacks, especially if the user
is rejecting cookies.

Bob Barrows
 
T

Tammy B.

Good idea. Probably the best Idea yet.
I am not there mentally yet, else I would not be pitchfork fighting in
Arron Bertrand hell right now.

He doesn't know if I'll be able to store a class in Session either.
Thank you.
 
A

Aaron Bertrand - MVP

He doesn't know if I'll be able to store a class in Session either.

Have you thought of, hmmm, I don't know, TRYING IT?
 
B

Bob Barrows

Well, seeing as how I'm on a roll ... :)

For that matter, you can also use a disconnected recordset, which can also
be saved to a file and reopened as necessary. It can even be reconnected to
the database so any changes can be propogated to the database using
UpdateBatch.

HTH,
Bob Barrows
 
T

Tammy B.

I did, but I can't get it to work.
So I need to know if it is something I am doing wrong , or if it is not
possible. That's why I to get someone WHO KNOWS to answer the question, and
to get YOU to STEP ASIDE

Will you keep me in your kill file
ps. have a good weekend
 
T

Tammy B.

holy moly that sounds good, I thought i was using a disconnected recordset.

save to what kind of file? text? xml? a recordset file? where on the client?
server?
 
B

Bob Barrows

Tammy said:
holy moly that sounds good, I thought i was using a disconnected
recordset.

You only have a disconnected recordset if you've opened it and subsequently
set its ActiveConnection property to Nothing (which explains its name ...)
save to what kind of file? text? xml? a recordset file?
Either a proprietary recordset format file, or an xml file. See here:
http://msdn.microsoft.com/library/en-us/ado270/htm/mdamth03_10.asp

where on the
client? server?

I was thinking of saving it on the server. You won't be able to save a file
on the client machine due to security reasons, unless you go the HTA route
(HTML Application).

If you want to pass the recordset to the client page, you can do something
like this:

http://www.davidpenton.com/testsite/tips/xml.recordset.server2client.asp

If you change the recordset in client-side code (add or change data, that
is), passing the changed recordset back to a server-side page would require
saving it to an xml document and putting the xml document's xml into a
hidden textbox ... I've never done this part so I'm making this up as I go
.... :) I don't see why it wouldn't work ...

Of course, the client machine will have to have a functioning MDAC
installation in order for any of this client-side stuff to work. This alone
may be enough to convince you to do ADO stuff on the server only.

It's a lot easier to pass an xml document to the client. See here:
http://www.davidpenton.com/testsite/tips/xml.data.islands.asp

HTH,
Bob Barrows
 
C

Chris Barber

I may be wrong but I believe that VBScript classes cannot be stored in
session variables (sort of remember a Michael Harris post).
Also discussed here:
http://aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=195

A lot of the possibilitites discussed here seem a bit overly complex?

Here's my list of possible solutions:
An XML document (stored as a single string session variable) would do the
trick.
A WSC component (eg. same as a DLL but scripted code and no requirement to
recompile to make change) that either stores the data in session variable(s)
or a database. WSC's expose intellisense etc. to Interdev so they are a
slightly more complex version of VBScript classes that are also COM objects
in their own right.
A simple state VB DLL would also suffice (before I get flamed - I know there
are a multitiude of issues with *VB* DLLs in that they are apartment
threaded and give rise to all sorts of scaleability issues).
A stateless VB DLL (or hosted in MTS would be better) that stores and
retrieves from a database.
Data stored diretly in a database.

All of them have issues mostly concerning complexity, state management and
scaleability.

The simplest in my mind to achieve the required results would be an XML
document with the XML string stored in a single session variable (or
database for that matter). Also has the added benefit that it can be
communicated with from the client side (with client side XML support of
course).

Anyway - that's my meagre thoughts.

Cheers,

Chris.
 
B

Bob Barrows

Tammy said:
ok so I'm doing that. so I guess i need to save it as <another>
diconnected recordset - as a file ..?
? Another recordset?
No. Just save your disconnected recordset to a file. You'll have to use some
sort of naming scheme so you can identify the proper file. When the next
page opens, create a recordset object, check to see if the file exists. If
it does, instead of using a database connection to open it, use the file's
name in the Open statement. I think I posted an example of doing this in the
past week. Off to Google .... Here it is:
http://tinyurl.com/fz9p

HTH,
Bob Barrows
 

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

Forum statistics

Threads
474,123
Messages
2,570,728
Members
47,289
Latest member
NicholeC11

Latest Threads

Top