Objects stored in session using Sql Server

Discussion in 'ASP General' started by wdudek, Feb 26, 2008.

  1. wdudek

    wdudek Guest

    We have a website that works fine when hosted on a single server, however it
    experiences some strange problems when run on a web farm using SQL Server to
    handle session state. When running on the farm, in the same method call an
    object that just had a value set will no longer have the value set a couple
    of lines later. In this example the object is pulled out of session, altered
    and placed back in session before a following line of code tries to use the
    altered value, only to find out that it appears to have never been changed.
    The application essentially stores 1 object that contains several other
    objects in session. The group that manages teh web farm is telling me that
    this is the problem. They are saying that because of the
    serialization/deserialization in sql server, the reference to the inner
    objects isn't flowing through to the object being stored in SQL Server. Does
    this sound correct? Should there be any differance between how a website code
    funcitons on a single server versus a web farm? They provided me with the
    below documentation, but have not yet been able to tell me where it came
    from. This has been an ongoing battle over who's problem it really is, any
    information on this subject will be appreciated.

    Thanks,

    Bill

    This is the reponse I got from our techincal support group
    There is no problem with the SQL Server settings for storing the session as
    session objects get created, retrieved and updated in the SQL Server. The
    issue is with the way the session object is updated in the C# code.

    Session in asp.net behaves as follows.

    InProc: In this mode session data is stored in the AppDomain of the
    application. All the objects stored in the session are actually stored in
    AppDomain and a reference is created for the session.

    SQL Server/State Server: In this mode session data is serialized and stored
    in SQL server database. When sessions is loaded system will fetch the data
    from database and deserialize it and creates the objects with deserialize
    data and bind them to state bag. In this mode the actual object references
    and session object references are different.

    Because of this, the S&S application is able to retrieve data when session
    is in InProc but not in SQL Server. What's happening in S&S application is as
    below.

    In case of InProc session Inquiry object and Search object have
    same reference, so updating one object is will show effect all its references.

    In case of SQL Server session each object will have its own
    reference (each time new object is created from deserialize data), so
    updating one object will not update the other object in the session.

    To solve this, C# code needs to be modified where the session related
    objects are updated such that it gets updated in the session correctly.
     
    wdudek, Feb 26, 2008
    #1
    1. Advertising

  2. wdudek wrote:
    > We have a website that works fine when hosted on a single server,
    > however it experiences some strange problems when run on a web farm
    > using SQL Server to handle session state.


    There was no way for you to know it (except maybe by browsing through
    some of the previous questions before posting yours - always a
    recommended practice), but this is a classic asp newsgroup. ASP.Net is
    a different technology from classic ASP. While you may be lucky enough
    to find a dotnet-savvy person here who can answer your question, you
    can eliminate the luck factor by posting your question to a newsgroup
    where the dotnet-savvy people hang out. I suggest
    microsoft.public.dotnet.framework.aspnet.
    There are also forums at www.asp.net where you can find a lot of people
    to help you.


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Feb 26, 2008
    #2
    1. Advertising

  3. wdudek

    Steven Cheng Guest

    Hi Bill,

    As for the "document" you mentioned for ASP.NET session state, I think the
    IT guys on your side pick up them from the MSDN document of ASP.NET session
    state settings. Yes, for SQL server session mode, it require all the
    objects(that'll be stored in it) to be serializable. However, I still not
    sure whether this is the exact cause of your problem since serializable
    class objects should be stored in session state correctly. Would you post
    some info of the class(that cause the problem) or a simplified class that
    can demonstrate this same problem. If you haven't tested some other class
    or simple types, I suggest you try performing the same test with some other
    built-in simple types or custom types(be serializable) to see whether the
    same problem will occur.

    Also, as Bob suggest, you should post such kind of ASP.NET issues in the
    ASP.NET newsgroups such as microsoft.public.dotnet.framework.aspnet

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: =?Utf-8?B?d2R1ZGVr?= <>
    >Subject: Objects stored in session using Sql Server
    >Date: Tue, 26 Feb 2008 11:32:02 -0800


    >
    >We have a website that works fine when hosted on a single server, however

    it
    >experiences some strange problems when run on a web farm using SQL Server

    to
    >handle session state. When running on the farm, in the same method call an
    >object that just had a value set will no longer have the value set a

    couple
    >of lines later. In this example the object is pulled out of session,

    altered
    >and placed back in session before a following line of code tries to use

    the
    >altered value, only to find out that it appears to have never been

    changed.
    >The application essentially stores 1 object that contains several other
    >objects in session. The group that manages teh web farm is telling me that
    >this is the problem. They are saying that because of the
    >serialization/deserialization in sql server, the reference to the inner
    >objects isn't flowing through to the object being stored in SQL Server.

    Does
    >this sound correct? Should there be any differance between how a website

    code
    >funcitons on a single server versus a web farm? They provided me with the
    >below documentation, but have not yet been able to tell me where it came
    >from. This has been an ongoing battle over who's problem it really is, any
    >information on this subject will be appreciated.
    >
    >Thanks,
    >
    >Bill
    >
    >This is the reponse I got from our techincal support group
    >There is no problem with the SQL Server settings for storing the session

    as
    >session objects get created, retrieved and updated in the SQL Server. The
    >issue is with the way the session object is updated in the C# code.
    >
    >Session in asp.net behaves as follows.
    >
    >InProc: In this mode session data is stored in the AppDomain of the
    >application. All the objects stored in the session are actually stored in
    >AppDomain and a reference is created for the session.
    >
    >SQL Server/State Server: In this mode session data is serialized and

    stored
    >in SQL server database. When sessions is loaded system will fetch the data
    >from database and deserialize it and creates the objects with deserialize
    >data and bind them to state bag. In this mode the actual object references
    >and session object references are different.
    >
    >Because of this, the S&S application is able to retrieve data when session
    >is in InProc but not in SQL Server. What's happening in S&S application is

    as
    >below.
    >
    > In case of InProc session Inquiry object and Search object

    have
    >same reference, so updating one object is will show effect all its

    references.
    >
    > In case of SQL Server session each object will have its own
    >reference (each time new object is created from deserialize data), so
    >updating one object will not update the other object in the session.
    >
    >To solve this, C# code needs to be modified where the session related
    >objects are updated such that it gets updated in the session correctly.
    >
    >
     
    Steven Cheng, Feb 27, 2008
    #3
  4. wdudek

    wdudek Guest

    Thanks,

    I didn't realize this wasn't and asp.net group. I'll give your advice a
    try and also repost in the suggested group.

    ""Steven Cheng"" wrote:

    > Hi Bill,
    >
    > As for the "document" you mentioned for ASP.NET session state, I think the
    > IT guys on your side pick up them from the MSDN document of ASP.NET session
    > state settings. Yes, for SQL server session mode, it require all the
    > objects(that'll be stored in it) to be serializable. However, I still not
    > sure whether this is the exact cause of your problem since serializable
    > class objects should be stored in session state correctly. Would you post
    > some info of the class(that cause the problem) or a simplified class that
    > can demonstrate this same problem. If you haven't tested some other class
    > or simple types, I suggest you try performing the same test with some other
    > built-in simple types or custom types(be serializable) to see whether the
    > same problem will occur.
    >
    > Also, as Bob suggest, you should post such kind of ASP.NET issues in the
    > ASP.NET newsgroups such as microsoft.public.dotnet.framework.aspnet
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    > --------------------
    > >From: =?Utf-8?B?d2R1ZGVr?= <>
    > >Subject: Objects stored in session using Sql Server
    > >Date: Tue, 26 Feb 2008 11:32:02 -0800

    >
    > >
    > >We have a website that works fine when hosted on a single server, however

    > it
    > >experiences some strange problems when run on a web farm using SQL Server

    > to
    > >handle session state. When running on the farm, in the same method call an
    > >object that just had a value set will no longer have the value set a

    > couple
    > >of lines later. In this example the object is pulled out of session,

    > altered
    > >and placed back in session before a following line of code tries to use

    > the
    > >altered value, only to find out that it appears to have never been

    > changed.
    > >The application essentially stores 1 object that contains several other
    > >objects in session. The group that manages teh web farm is telling me that
    > >this is the problem. They are saying that because of the
    > >serialization/deserialization in sql server, the reference to the inner
    > >objects isn't flowing through to the object being stored in SQL Server.

    > Does
    > >this sound correct? Should there be any differance between how a website

    > code
    > >funcitons on a single server versus a web farm? They provided me with the
    > >below documentation, but have not yet been able to tell me where it came
    > >from. This has been an ongoing battle over who's problem it really is, any
    > >information on this subject will be appreciated.
    > >
    > >Thanks,
    > >
    > >Bill
    > >
    > >This is the reponse I got from our techincal support group
    > >There is no problem with the SQL Server settings for storing the session

    > as
    > >session objects get created, retrieved and updated in the SQL Server. The
    > >issue is with the way the session object is updated in the C# code.
    > >
    > >Session in asp.net behaves as follows.
    > >
    > >InProc: In this mode session data is stored in the AppDomain of the
    > >application. All the objects stored in the session are actually stored in
    > >AppDomain and a reference is created for the session.
    > >
    > >SQL Server/State Server: In this mode session data is serialized and

    > stored
    > >in SQL server database. When sessions is loaded system will fetch the data
    > >from database and deserialize it and creates the objects with deserialize
    > >data and bind them to state bag. In this mode the actual object references
    > >and session object references are different.
    > >
    > >Because of this, the S&S application is able to retrieve data when session
    > >is in InProc but not in SQL Server. What's happening in S&S application is

    > as
    > >below.
    > >
    > > In case of InProc session Inquiry object and Search object

    > have
    > >same reference, so updating one object is will show effect all its

    > references.
    > >
    > > In case of SQL Server session each object will have its own
    > >reference (each time new object is created from deserialize data), so
    > >updating one object will not update the other object in the session.
    > >
    > >To solve this, C# code needs to be modified where the session related
    > >objects are updated such that it gets updated in the session correctly.
    > >
    > >

    >
    >
     
    wdudek, Feb 27, 2008
    #4
  5. wdudek

    Steven Cheng Guest

    Thanks for your reply Bill,

    Please feel free to followup in the new thead.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >Thread-Topic: Objects stored in session using Sql Server
    >thread-index: Ach5d7Prt67tj9RsQyeNLimLOjEeMQ==
    >X-WBNR-Posting-Host: 199.106.94.142
    >From: =?Utf-8?B?d2R1ZGVr?= <>
    >References: <>

    <>
    >Subject: RE: Objects stored in session using Sql Server
    >Date: Wed, 27 Feb 2008 11:34:00 -0800


    >
    >Thanks,
    >
    > I didn't realize this wasn't and asp.net group. I'll give your advice

    a
    >try and also repost in the suggested group.
    >
    >""Steven Cheng"" wrote:
    >
    >> Hi Bill,
    >>
    >> As for the "document" you mentioned for ASP.NET session state, I think

    the
    >> IT guys on your side pick up them from the MSDN document of ASP.NET

    session
    >> state settings. Yes, for SQL server session mode, it require all the
    >> objects(that'll be stored in it) to be serializable. However, I still

    not
    >> sure whether this is the exact cause of your problem since serializable
    >> class objects should be stored in session state correctly. Would you

    post
    >> some info of the class(that cause the problem) or a simplified class

    that
    >> can demonstrate this same problem. If you haven't tested some other

    class
    >> or simple types, I suggest you try performing the same test with some

    other
    >> built-in simple types or custom types(be serializable) to see whether

    the
    >> same problem will occur.
    >>
    >> Also, as Bob suggest, you should post such kind of ASP.NET issues in the
    >> ASP.NET newsgroups such as microsoft.public.dotnet.framework.aspnet
    >>
    >> Sincerely,
    >>
    >> Steven Cheng
    >>
    >> Microsoft MSDN Online Support Lead
    >>
    >> >>

    >
     
    Steven Cheng, Feb 28, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Collins
    Replies:
    5
    Views:
    1,989
    Jason Collins
    Aug 28, 2003
  2. Michael
    Replies:
    2
    Views:
    660
    Michael
    Nov 26, 2005
  3. Michael
    Replies:
    3
    Views:
    1,154
    Jim Cheshire
    Dec 30, 2005
  4. Mufasa
    Replies:
    1
    Views:
    316
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 8, 2007
  5. sunkrajesh
    Replies:
    0
    Views:
    362
    sunkrajesh
    May 31, 2009
Loading...

Share This Page