using session object vs. module.vb

S

semsem22

hello, i m new to ASP.NET, but have experience with VB6....i have a couple of questions about the use of a module and the decleration of public objects in the module vs the use of sessions

the main issue i am concerned with is performance....i would like to create a public object called Client, then i can set its properties from a Database, and have that object alive for the duration of the user's interaction with the system.....which helps me a great deal because i use the properties of the client object quite alot, i also want to create a public object of type Dataset that i can fill and test on from anywhere in the application.....however, i am concerned that as the system becomes more popular, and there are a number of concurrent users, that may be a strain on the server's memory to have global objects for each user....is this correct, or have i miss understood this?

in my search for answers, i have come across the use of session states, to hold objects or variables...is this better in terms of performance than using global objects, and if so, how can retrieve a specific property of an object stored in a session variable



any help would be appreciated, thank you very much

sameh

From http://www.developmentnow.com/g/8_2003_11_0_3_0/dotnet-framework-aspnet.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
D

David Browne

semsem22 said:
hello, i m new to ASP.NET, but have experience with VB6....i have a couple
of questions about the use of a module and the decleration of public
objects in the module vs the use of sessions

the main issue i am concerned with is performance....i would like to
create a public object called Client, then i can set its properties from a
Database, and have that object alive for the duration of the user's
interaction with the system.....which helps me a great deal because i use
the properties of the client object quite alot, i also want to create a
public object of type Dataset that i can fill and test on from anywhere in
the application.....however, i am concerned that as the system becomes
more popular, and there are a number of concurrent users, that may be a
strain on the server's memory to have global objects for each user....is
this correct, or have i miss understood this?

in my search for answers, i have come across the use of session states, to
hold objects or >variables...is this better in terms of performance than
using global objects,

Global objects are just wrong for this. Global objects are not limited to
the user's session. They are shared across all user sessions. The session
object is what you want. Some care must be taken with stuffing data into
the session state, but when you divide the available server memory by the
maximum number of concurrent sessions you will often find that this is not
really an issue (especially now that .NET 2.0 lets you run your web site on
64-bit machines).
and if so, how can retrieve a specific property of an object stored in a
session variable

Session is basically a Hashtable, so you stuff something in with a key:

Session("UserProfile") = MyUserProfileObject

And pull it back out using the same key

dim MyUserProfileObject as MyUserProfile =
DirectCast(Session("UserProfile"),MyUserProfile)




David
 
S

semesm22

thank you very much for your reply, however i am wondering what this
code does

DirectCast(Session("UserProfile",MyUserProfile)

what does DirectCast do for session object

thank you
sam
 
D

David Browne

semesm22 said:
thank you very much for your reply, however i am wondering what this
code does

DirectCast(Session("UserProfile",MyUserProfile)

what does DirectCast do for session object


dim MyUserProfileObject as MyUserProfile =
DirectCast(Session("UserProfile"),MyUserProfile)

This extracts an object of type MyUserProfile (which you would have to
write) from the session object. When you pull it out of session it is
upcast to an Object. DirectCast downcasts to the MyUserProfile type before
assigning it to the variable. If you turn OPTION STRICT off the DirectCast
is not needed.

David
 
S

semesm22

i would like to do the following....i have a ConnectDB class, that
imports system.data.ole, and i have the OleConnection, and OleCommand,
and a SQL string as a property in that class....the idea is that i can
set the SQL property from any web form, and call a login method that
will connect to the datebase and select * from client, for example, and
put the data in a Dataset.....what i would like to do is to add this
dataset to the session object, so that i can check to see if there were
records found in the database from the web form that called the Login
method...here is the code i m using, cause i don't think i'm explaining
this well!!!

public class ConnectDB

*** i nitialize the connection string, and the OleConnection,
OleCommand, and DataAdapter here***

public sub Login()

'SQL statment set from any page
OleCommand.CommandText = me.SQL
OleCommand.Connection = OleConnection

try
OleConnection.Open
dim myDataset as new Dataset
DataAdapter.Fill(myDataset)
catch
end try
end class

*************************************************************
now what i would like to do is to assign myDataset to a session
object....is this even possible?, if so, how can i do that? if not, then
what is a better solution?
************************************************************
public class WebForm1

private sub Login_Click()

dim myConnectDB as new ConnectDB

myConnectDB.SQL = "select * from client where name = '" & txtName.text &
"'"
myConnectDB.Login

end class


PLEASE HELP


thank you
sam
 

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,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top