SQL Server session not working...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was using session mode as "InProc"(entered in web.config). I have deployed
my ASP.NET appln. on a server which uses Load Balancer. i.e I have two
servers. I am using session across pages.The problem I was facing is that
sometimes I find the session and sometimes not. I beleive this is happenning
because of multiple servers. Because session is created on a worker process
on one server and the second time it must be hitting the other server to
fetch the
session. Hence the issue.I then used SQL Server session mode but now I get
the errror "Unable to serialize the session state. Please note that
non-serializable objects or MarshalByRef objects are not permitted when
session state mode is 'StateServer' or 'SQLServer'. "
Any Idea ? Thanks in advance..
 
If there is something that does not need to be serialized, make them
non-public or decorate then with Non-serialzable attribute. You will have to
look at your objects closely to make the decision. and if there is something
that needs to be serialzable and by default does not do it by itself then
you will have to manually serialize those objects.
Also put [Serializable] attributes on your objects.
 
note: some object can not be serialized, such as sqlconnections,
datareaders, streams, com interop objects, collections containing a
non-serializable object, etc. in this case you must be redesign you session
data.

you'd think, when asp.net tried to serialize session data, it would list the
name of the object. to find the offending object:

try (air code)

MemoryStream myWriter = new MemoryStream ();
foreach (string key in Session.AllKeys)
{
object o = Session[key];
try
{
XmlSerializer mySerializer = new XmlSerializer(o.GetType());
mySerializer.Serialize(myWriter, o);
}
catch
{
Debug.Print("Unable to serialize: " + key);
}
}
myWriter.Close();


-- bruce (sqlwork.com)




-- bruce (sqlwork.com)




Winista said:
If there is something that does not need to be serialized, make them
non-public or decorate then with Non-serialzable attribute. You will have
to look at your objects closely to make the decision. and if there is
something that needs to be serialzable and by default does not do it by
itself then you will have to manually serialize those objects.
Also put [Serializable] attributes on your objects.

NAT said:
So do I need to serialize it ? How can i ?
 
Back
Top