Ask a Question related to ASP.NET General, Design and Development.
-
Tommy Christian #1
Saving serialized data to database problem
Hi!
Anyone who knows about saving serialized data to database,
coz I have a problem with that. If I just serialize my session data and
then deserialize it, it works. But when I save it between those actions into
Oracle database into long row field, it doesn´t. Below is some code.
Thanks for everyone, if you know what helps.
'HERE IT SAVE´S SERIALIZED DATA TO DATABASE
Function Update()
Dim oSessionDataStream As New MemoryStream()
oSessionDataStream = Me.Serialize
'Me.Serialize is serialized data in a stream
Dim oByteArray(oSessionDataStream.Length - 1) As Byte
oSessionDataStream.Read(oByteArray, 0, oByteArray.Length)
Dim sSessionUpdateSql As String = "UPDATE TABLE SET (SDATA) = (?) WHERE
ID ='" & Me.Id & "'"
Dim oSessionDataUpdateCommand As OleDb.OleDbCommand = New
OleDbCommand(sSessionUpdateSql, Me.mWebPage.Database.Connection)
oSessionDataUpdateCommand.Parameters.Add("@SDATA",
System.Data.OleDb.OleDbType.Binary, oSessionDataStream.Length).Value =
oByteArray
oSessionDataUpdateCommand.ExecuteNonQuery()
oSessionDataStream.Close()
End Function
'HERE WE GET DATA FROM DATABASE
Public Function Retrieve() As MemoryStream
Dim sSessionRetrieveSql As OleDbCommand = New OleDbCommand("SELECT SDATA
FROM TABLE WHERE SID = '" & Me.Id & "'", mWebPage.Database.Connection)
Dim oReader As OleDbDataReader
oReader = sSessionRetrieveSql.ExecuteReader()
oReader.Read()
Dim b(oReader.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
oReader.GetBytes(0, 0, b, 0, b.Length)
oReader.Close()
Dim oStream As New MemoryStream(b)
oStream.Write(b, 0, b.Length)
Return oStream
End Function
'HERE WE TRY TO DESERIALIZE DATA.
Public Function Deserialize(ByVal oStream As MemoryStream) As Session
Dim oFormatter As New BinaryFormatter()
oStream.Position = 0
Return DirectCast(oFormatter.Deserialize(oStream), Session)
End Function
'HERE IS THE ERROR WHICH COMES IN THE LAS ROW. (Return
DirectCast(oFormatter.Deserialize(oStream), Session))
System.Runtime.Serialization.SerializationExceptio n - Binary stream does not
contain a valid BinaryHeader, 0 possible causes, invalid stream or object
version change between serialization and deserialization.
'XML SERIALIZATION GIVES ERROR
root does not excist.
Tommy Christian Guest
-
problem saving form results to a database table
Coldfusion MX MSDE 2000 I have a form on a page which users either fill in text or check radio buttons. The form has the following properties:... -
Saving image in database.........
Hi i'm from venezuela sorry for my english. I have a problem i need to make a site more dynamic, so i need to pass all data from txt file to mysql... -
Problem saving data and closing popup windows
I seem to be missing something, but don't know what. :confused; I have a screen from which a user can click on a button that brings up a popup... -
Problem with viewing database data
Good Morning, Here is the problem: When I am viewing comments from the database on my processing page and they are quite long, my page layout... -
NEWBIE HELP Import Data from flat-database to relational-database
I want to import Data from a simple Database, which contains all Information in one big record into a relational Database and split up the big...



Reply With Quote

