473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem with a DataRow in Session

Hi,

Database: SQL Server
Session: SQL Server
Language: C#
Application: ASP.Net

I have created a login page which attempts to retrieve the users record
from the database and I store the validated users DataRow into Session
which is in SQLServer. I have listed the error below for you to
review. I
can successfully store a DataRow on other pages. I don't understand
why it will work for one page and not the other.

The Error:

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'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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'.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[SerializationException: The type System.Xml.XmlBoundElement in
Assembly System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 is not marked as serializable.]

System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType
type, Boolean excludeNonSerializable) +868

System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type
type, StreamingContext context) +300

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()
+103

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +362

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +48

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +601

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
+738

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
+136
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1621

[HttpException (0x80004005): 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'.]
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1710
System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter
writer) +148

System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
item, Stream stream) +146

System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String
id, SessionStateItem item, Boolean inStorage) +126
System.Web.SessionState.SessionStateModule.OnRelea seState(Object
source, EventArgs eventArgs) +465

System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +87

Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032

Nov 19 '05 #1
5 5669
For objects to be stored in the SqlSever Session State mechanism, they need
to be able to be serialized. This typically means adding the [Serializable]
attribute to the class. It's essentially a permission slip to let the runtime
take all of the object's state and save it elsewhere (like a binary stream,
which might live in a file or in a database). The DataRow is not marked with
that attribute, thus it hasn't granted permission. IIRC, the DataTable and
DataSet are Serialazible, but those are fairly heavy weight objects to shove
into Session in your database. Consider storing your data in a more light-weight
mannger, perhaps as an array or ArrayList.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

Database: SQL Server
Session: SQL Server
Language: C#
Application: ASP.Net
I have created a login page which attempts to retrieve the users
record
from the database and I store the validated users DataRow into Session
which is in SQLServer. I have listed the error below for you to
review. I
can successfully store a DataRow on other pages. I don't understand
why it will work for one page and not the other.
The Error:

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'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: 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'.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[SerializationException: The type System.Xml.XmlBoundElement in
Assembly System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 is not marked as serializable.]

System.Runtime.Serialization.FormatterServices.Int ernalGetSerializable
Members(RuntimeType type, Boolean excludeNonSerializable) +868

System.Runtime.Serialization.FormatterServices.Get SerializableMembers(
Type type, StreamingContext context) +300

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMem
berInfo() +103

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSer
ialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +362
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Seriali
ze(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +48
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(Writ
eObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo
typeNameInfo) +601

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(
Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
+738
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Seriali
ze(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
+136
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1621
[HttpException (0x80004005): 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'.]
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1710
System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter
writer) +148
System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
item, Stream stream) +146

System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.
IStateClientManager.Set(String
id, SessionStateItem item, Boolean inStorage) +126
System.Web.SessionState.SessionStateModule.OnRelea seState(Object
source, EventArgs eventArgs) +465
System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutio
nStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step,
Boolean&
completedSynchronously) +87
Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032


Nov 19 '05 #2
While the DataRow is marked as serializable, it's Element property isn't.
It might have worked on some pages because this property was null, and not
on login because it isn't. Since Element property is only used internally,
my guess is that the difference between the two is in how it was created.

You could always use the datarow.ItemArray to get an array of objects...or
map the datarow to a custom User class

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"sdettmers" <sd*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

Database: SQL Server
Session: SQL Server
Language: C#
Application: ASP.Net

I have created a login page which attempts to retrieve the users record
from the database and I store the validated users DataRow into Session
which is in SQLServer. I have listed the error below for you to
review. I
can successfully store a DataRow on other pages. I don't understand
why it will work for one page and not the other.

The Error:

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'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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'.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[SerializationException: The type System.Xml.XmlBoundElement in
Assembly System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 is not marked as serializable.]

System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType
type, Boolean excludeNonSerializable) +868

System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type
type, StreamingContext context) +300

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()
+103

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +362

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +48

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +601

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
+738

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
+136
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1621

[HttpException (0x80004005): 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'.]
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1710
System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter
writer) +148

System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
item, Stream stream) +146

System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String
id, SessionStateItem item, Boolean inStorage) +126
System.Web.SessionState.SessionStateModule.OnRelea seState(Object
source, EventArgs eventArgs) +465

System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +87

Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032

Nov 19 '05 #3
Brock

Thanks for the reply, I appreciate the help. I noticed that on the
microsoft web site they show the DataRow as a Serializable class. I
have posted the link below.

http://msdn.microsoft.com/library/de...classtopic.asp

Nov 19 '05 #4
Karl,

I think you are on to something. On the pages where successfully
storing the DataRow I get the object from SQL but on the login page I
create a dummy DataRow incase the user record was not found in the
database. This was to avoid returning null on the call. I will have
to come up with a new way of handling the null return or create DTO
objects to store the data in Session.
Thanks for your help

Nov 19 '05 #5
Interesting. I was looking at the 2.0 docs and had looked at the 2.0 version
of System.Data.dll, where it is not serializable.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Brock

Thanks for the reply, I appreciate the help. I noticed that on the
microsoft web site they show the DataRow as a Serializable class. I
have posted the link below.

http://msdn.microsoft.com/library/de...ry/en-us/cpref
/html/frlrfsystemdatadatarowclasstopic.asp


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Newbie | last post by:
I am using a Datagrid to show the contents of a DataTable. But it seems like the Datagrid is not getting the contents of the Datatable when the button ( btnAddAnotherLaborCategory) is clicked. ...
2
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
10
by: Brian Henry | last post by:
Hi, I am having a problem with an attachment system I made... it works with files up to ~3MB in size then after that if you try to upload a file it just goes to a "Page can not be displayed" page...
2
by: wolfgang wagner | last post by:
hi all! im trying to edit data in a datagrid (like described here: http://aspnet.4guysfromrolla.com/articles/071002-1.aspx) but if i click the edit button i get the following error invalid...
8
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter =...
2
by: Victor | last post by:
When I loop through a datatable rows and add Amt field content (which is float in database) sometimes it adds upto High Precision value leaving a difference of -1.81898940354586E-12 though I am...
1
by: dhyder | last post by:
OK, like the title says my error is Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. I have looked into this a lot, but have not...
1
by: mercea | last post by:
Hi guys, I am taking a column from a table and comparing each row in that table with a similar column in a gridview row by row. For each identical answer, grade increments by 1. after all the rows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.