What's better: using Application or Session object?? (in my case)

K

kito

Hi,

I wanted to get some advices from you guys.
I have a little web-shop in ASP.NET for a project. I have several VB
classes, where the most important ones are the "DBmanager" and the
"DataManager". The DBManager creates the database connection and has
some useful functions. The DataManager has an Object of the DBManager
and uses that functions to get the Data as DataView, DataReader,....

Now to avoid that every time a user accesses the page, there is always
created a new Object of the DataManager and therefore also of the
DBManager which means also a new connection to the database, I wanted
to store the objects in the Session or Application object.

It is clear to me, that storing in the Session variable would meen that
it is specific for each user, meaning again that so for each
user-session those objects would be created. On the other hand, the
Application object would sound better to me, since in that case only at
each Application - start the objects would be created.

Can you give me advices. They can also be of completely different
nature.

thanks
Juri
 
L

Laurent Bugnion

Hi,
Hi,

I wanted to get some advices from you guys.
I have a little web-shop in ASP.NET for a project. I have several VB
classes, where the most important ones are the "DBmanager" and the
"DataManager". The DBManager creates the database connection and has
some useful functions. The DataManager has an Object of the DBManager
and uses that functions to get the Data as DataView, DataReader,....

Now to avoid that every time a user accesses the page, there is always
created a new Object of the DataManager and therefore also of the
DBManager which means also a new connection to the database, I wanted
to store the objects in the Session or Application object.

It is clear to me, that storing in the Session variable would meen that
it is specific for each user, meaning again that so for each
user-session those objects would be created. On the other hand, the
Application object would sound better to me, since in that case only at
each Application - start the objects would be created.

Can you give me advices. They can also be of completely different
nature.

thanks
Juri

Storing data in the Application has one additional disadvantage (other
than that it is not user-specific (actually, session-specific): It
requests careful management of stored data. The Application is recycled
only seldomly. If you forget to delete data stored in it, there is a
risk to create memory leaks. On the other hand, Sessions usually time
out after 20 minutes (that is, 20 minutes after the last access to
dynamic content). This minimizes the risk.

HTH,
Laurent
 
K

kito

I know, therefore I do the following on startup, where the
Application_start event is fired:
Dim dbManager as new DBManager
Dim dataManager as new DataManager(dbManager)
Application("DBManager") = dbManager
Application("DataManager") = dataManager

In the method of the Application_end event, i do then the following:
Application("DBManager") = Nothing
Application("DataManager") = Nothing

May it also be better to lock the Application before writing?? Maybe
safer...
Anyway...what do you suggest me to use? In your opinion.

I think putting it into the Session variable could be also a Memory
issue. What if 100 or say more, load the webpage. Then 100 objects
would be created and with all of them also a DBConnection or not? I
mean in my case this will not happen, since it is only a project for
the University, but it will be marked for such things.

Thanks again

Juri
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top