Ok, I must be doing something very simply wrong.

global.asa:
---------------------------------------------------------------------
<script language="vbscript" runat="server">

Sub Session_OnStart
Dim oProduct, sTemp
Set oProduct = New SampleProduct

sTemp = "ABC123"
oProduct.SKU = "ABC123"
oProduct.Name = "My Killer Product"

Set Session(sTemp) = oProduct
End Sub

Class SampleProduct

Public SKU
Public Name

End Class

</script>
---------------------------------------------------------------------
My asp code looks like this:
---------------------------------------------------------------------
Dim oMyProduct
Set oMyProduct = Session("ABC123")

Response.Write(oMyProduct.Name)
---------------------------------------------------------------------
All I get is:
---------------------------------------------------------------------
Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Name'

/Testing.asp, line 14
---------------------------------------------------------------------

Am I retarded? What am I missing?
Thanks for any help.

Re: Classes in Session Variables - What's my problem? by Ayush

Ayush
Wed Jan 24 17:45:35 CST 2007

Replied to [Beav]s message :
> Ok, I must be doing something very simply wrong.
>
> global.asa:
> ---------------------------------------------------------------------
> <script language="vbscript" runat="server">
>
> Sub Session_OnStart
> Dim oProduct, sTemp
> Set oProduct = New SampleProduct
>
> sTemp = "ABC123"
> oProduct.SKU = "ABC123"
> oProduct.Name = "My Killer Product"
>
> Set Session(sTemp) = oProduct
> End Sub


Use Function here if you want to return a value (i am not sure you can return an object).


--
â?? Ayush
-------------
Search - www.Google.com | Wikipedia - http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------

Re: Classes in Session Variables - What's my problem? by Beav

Beav
Wed Jan 24 18:22:06 CST 2007

OK, So how do I write a method of a user-defined class to return the
object itself. Such as:

Class Product

Public Color
Public Name

Public Function GetMe()
GetMe =3D Product
End Function

End Class

This doesn't seem to work. Any thoughts?


On Jan 24, 3:45=C2=A0pm, Ayush <"ayushmaan.j[aatt]gmail.com"> wrote:
> Replied to [Beav]s message :
>
>
>
>
>
> > Ok, I must be doing something very simply wrong.
>
> > global.asa:
> > ---------------------------------------------------------------------
> > <script language=3D"vbscript" runat=3D"server">
>
> > Sub Session_OnStart
> > =C2=A0 =C2=A0Dim oProduct, sTemp
> > =C2=A0 =C2=A0Set oProduct =3D New SampleProduct
>
> > =C2=A0 =C2=A0sTemp =3D "ABC123"
> > =C2=A0 =C2=A0oProduct.SKU =3D "ABC123"
> > =C2=A0 =C2=A0oProduct.Name =3D "My Killer Product"
>
> > =C2=A0 =C2=A0Set Session(sTemp) =3D oProduct
> > End SubUse Function here if you want to return a value (i am not sure y=
ou can return an object).
>
> --
> =E2=86=92 Ayush
> -------------
> Search =C2=A0 =C2=A0-www.Google.com| Wikipedia =C2=A0 =C2=A0-http://en.wi=
kipedia.org
> Snip your long urls =C2=A0 -http://snipurl.com/
> -------------- Hide quoted text -- Show quoted text -


Re: Classes in Session Variables - What's my problem? by Michael

Michael
Wed Jan 24 18:42:48 CST 2007

Beav wrote:
> Ok, I must be doing something very simply wrong.
>

A must read (by Eric Lippert, the MS dev who implemented VBScript
classes)...

Using Classes with VBScript 5.0-- MIND November 1999
http://www.microsoft.com/mind/1199/classes/classes.asp

Note his remarks re: use across asp pages - "doubly doomed to failure" in
his words :-).

--
Michael Harris
Microsoft.MVP.Scripting



Re: Classes in Session Variables - What's my problem? by Beav

Beav
Wed Jan 24 19:01:52 CST 2007

Something must be lost in passing the object to the session.

When I move the code inline on the ASP, I can pass the object to the
Session variable, and then retrieve it just fine. But I must be doing
something wrong on the session onstart process.

On Jan 24, 3:36 pm, "Beav" <levibeck...@gmail.com> wrote:
> Ok, I must be doing something very simply wrong.
>
> global.asa:
> ---------------------------------------------------------------------
> <script language="vbscript" runat="server">
>
> Sub Session_OnStart
> Dim oProduct, sTemp
> Set oProduct = New SampleProduct
>
> sTemp = "ABC123"
> oProduct.SKU = "ABC123"
> oProduct.Name = "My Killer Product"
>
> Set Session(sTemp) = oProduct
> End Sub
>
> Class SampleProduct
>
> Public SKU
> Public Name
>
> End Class
>
> </script>
> ---------------------------------------------------------------------
> My asp code looks like this:
> ---------------------------------------------------------------------
> Dim oMyProduct
> Set oMyProduct = Session("ABC123")
>
> Response.Write(oMyProduct.Name)
> ---------------------------------------------------------------------
> All I get is:
> ---------------------------------------------------------------------
> Microsoft VBScript runtime error '800a01b6'
>
> Object doesn't support this property or method: 'Name'
>
> /Testing.asp, line 14
> ---------------------------------------------------------------------
>
> Am I retarded? What am I missing?
> Thanks for any help.


Re: Classes in Session Variables - What's my problem? by Beav

Beav
Fri Jan 26 18:55:46 CST 2007

Ok... so I figured out what my deal was.

In my global.asa, I was using a line:

Set Session(sSKU) = oProduct

I needed to use:

Execute("Set Session(""" & sSKU & """) = oProduct")

Now it works fine.

On Jan 24, 5:01 pm, "Beav" <levibeck...@gmail.com> wrote:
> Something must be lost in passing the object to the session.
>
> When I move the code inline on the ASP, I can pass the object to the
> Session variable, and then retrieve it just fine. But I must be doing
> something wrong on the session onstart process.
>
> On Jan 24, 3:36 pm, "Beav" <levibeck...@gmail.com> wrote:
>
>
>
> > Ok, I must be doing something very simply wrong.
>
> > global.asa:
> > ---------------------------------------------------------------------
> > <script language="vbscript" runat="server">
>
> > Sub Session_OnStart
> > Dim oProduct, sTemp
> > Set oProduct = New SampleProduct
>
> > sTemp = "ABC123"
> > oProduct.SKU = "ABC123"
> > oProduct.Name = "My Killer Product"
>
> > Set Session(sTemp) = oProduct
> > End Sub
>
> > Class SampleProduct
>
> > Public SKU
> > Public Name
>
> > End Class
>
> > </script>
> > ---------------------------------------------------------------------
> > My asp code looks like this:
> > ---------------------------------------------------------------------
> > Dim oMyProduct
> > Set oMyProduct = Session("ABC123")
>
> > Response.Write(oMyProduct.Name)
> > ---------------------------------------------------------------------
> > All I get is:
> > ---------------------------------------------------------------------
> > Microsoft VBScript runtime error '800a01b6'
>
> > Object doesn't support this property or method: 'Name'
>
> > /Testing.asp, line 14
> > ---------------------------------------------------------------------
>
> > Am I retarded? What am I missing?
> > Thanks for any help.- Hide quoted text -- Show quoted text -


Re: Classes in Session Variables - What's my problem? by Anthony

Anthony
Sun Jan 28 16:02:16 CST 2007


"Beav" <levibeckman@gmail.com> wrote in message
news:1169859346.618486.245380@h3g2000cwc.googlegroups.com...
> Ok... so I figured out what my deal was.
>
> In my global.asa, I was using a line:
>
> Set Session(sSKU) = oProduct
>
> I needed to use:
>
> Execute("Set Session(""" & sSKU & """) = oProduct")
>
> Now it works fine.
>

It may appear to work. However it is most seriously not recommended. If you
haven't read the link Michael posted let me just summarise one of the two
reasons this is a bad idea.

Normally when a server receives a request from a client it can choose to use
one of several idle worker threads to process the request.

When you place an object in session storage. All further requests for that
session must be serviced by the thread in which that object was created.

Hence if a subsequent requests comes in from that client and the worker
thread that it now has become affiliated with is busy processing another
request then the client's request will have to wait in a queue for this work
thread to become available. This situation is damaging to the applications
scalability since it can lead to a lopsided demand for a few threads whilst
other worker threads go idle with nothing to do.

If you want to store object data in a session serialise the to a string and
add methods to the object to serialise and deserialise hence an instance of
the object itself isn't stored in the session only it's state.

An alternative is to use XML via the FreeThreadedDOMDocument to store the
state of your object. You may find that you don't actuall need your on
classes in this case.

Yet another choice is to use a DB.

One other point, why are you storing this in the session at all? Does it
vary from session to session? If not use the Application object (where you
definitely can't use your object).

Anthony.



Re: Classes in Session Variables - What's my problem? by Justin

Justin
Mon Jan 29 13:27:40 CST 2007

On Sun, 28 Jan 2007 16:02:16 -0600, Anthony Jones <Ant@yadayadayada.com>=
=

wrote:
> "Beav" <levibeckman@gmail.com> wrote in message
> news:1169859346.618486.245380@h3g2000cwc.googlegroups.com...
>> I needed to use:
>>
>> Execute("Set Session(""" & sSKU & """) =3D oProduct")
>>
>> Now it works fine.
>
> It may appear to work. However it is most seriously not recommended.
> If you haven't read the link Michael posted let me just summarise one=

> of the two reasons this is a bad idea.
>
> Normally when a server receives a request from a client it can choose
> to use one of several idle worker threads to process the request.
>
> When you place an object in session storage. All further requests for=

> that session must be serviced by the thread in which that object was
> created.
>
> Hence if a subsequent requests comes in from that client and the
> worker thread that it now has become affiliated with is busy
> processing another request then the client's request will have to wait=

> in a queue for this work thread to become available. This situation
> is damaging to the applications scalability since it can lead to a
> lopsided demand for a few threads whilst other worker threads go idle=

> with nothing to do.

Considering that it's only going to work as long as IIS doesn't decide
to discard or re-use the script context it has cached, I doubt he will
ever get far enough with this scheme to run into such scalability
issues. Perhaps we could start a pool to guess how long it will take
before he's back with the same problem as before? :)

-- =

Justin Piper
Bizco Technologies
http://www.bizco.com/