473,765 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 oSessionDataStr eam As New MemoryStream()

oSessionDataStr eam = Me.Serialize
'Me.Serialize is serialized data in a stream

Dim oByteArray(oSes sionDataStream. Length - 1) As Byte

oSessionDataStr eam.Read(oByteA rray, 0, oByteArray.Leng th)

Dim sSessionUpdateS ql As String = "UPDATE TABLE SET (SDATA) = (?) WHERE
ID ='" & Me.Id & "'"

Dim oSessionDataUpd ateCommand As OleDb.OleDbComm and = New
OleDbCommand(sS essionUpdateSql , Me.mWebPage.Dat abase.Connectio n)

oSessionDataUpd ateCommand.Para meters.Add("@SD ATA",
System.Data.Ole Db.OleDbType.Bi nary, oSessionDataStr eam.Length).Val ue =
oByteArray

oSessionDataUpd ateCommand.Exec uteNonQuery()

oSessionDataStr eam.Close()

End Function

'HERE WE GET DATA FROM DATABASE

Public Function Retrieve() As MemoryStream

Dim sSessionRetriev eSql As OleDbCommand = New OleDbCommand("S ELECT SDATA
FROM TABLE WHERE SID = '" & Me.Id & "'", mWebPage.Databa se.Connection)

Dim oReader As OleDbDataReader

oReader = sSessionRetriev eSql.ExecuteRea der()

oReader.Read()

Dim b(oReader.GetBy tes(0, 0, Nothing, 0, Integer.MaxValu e) - 1) As Byte

oReader.GetByte s(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(ByV al oStream As MemoryStream) As Session

Dim oFormatter As New BinaryFormatter ()

oStream.Positio n = 0

Return DirectCast(oFor matter.Deserial ize(oStream), Session)

End Function

'HERE IS THE ERROR WHICH COMES IN THE LAS ROW. (Return
DirectCast(oFor matter.Deserial ize(oStream), Session))

System.Runtime. Serialization.S erializationExc eption - 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.
Nov 17 '05 #1
0 2689

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

Similar topics

4
10819
by: John Kandell | last post by:
Hi, I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this... --- Would someone be able to shed some light on what is the cost of saving a DataTable to session vs saving a custom object of the same data.
10
1701
by: Krakatioison | last post by:
Hi everyone, can someone point me to download of an example for saving and retrieving to/from MYSQL database. Or did anyone of you tried this and could share your code with me. I've got some data which needs to be put to mysql database using VB.NET and I can't figure this out. Thanks a lot. K.
11
2423
by: Tom | last post by:
I am planning on adding a Preferences form to my application and using the Property Grid to display the preferences to the user. What do you think would be the best way to save these preferences out to an XML file? Use the CAB (Configuration Application Block)? Save the preferences in a class object and serialize them out the the XML file? Write them out directly to the XML file? Other ways??? Just want to get some thoughts together......
7
1517
by: timb | last post by:
Hi, is it possible to access the properties of a class or structure in a for each statement? I want to iterate through the stirng properties in my class or structure and then write them away to the config file. thanks for your help in advance --
10
2360
by: Fabuloussites | last post by:
I'm considering deploying an application that will us an IP address locaiton database provided by Ip2location.com... http://www.ip2location.net/ip2location-dotnet-component.aspx their .net component reads data from a binary file. I'm guess i'm wondering which of the two options would be best. 1) read data from the binary files (~27 mb or so) 2) or query a sql DB with the same info.
5
1261
by: Ben Kim | last post by:
Hello all, We are diving into VB.NET 2005 head first, coming from a language called Clarion. What are some of the drawbacks, if any, to serialized objects? Should we just use streaming data? The environment will be as follows: Multiple data stores (could be SQL Server databases across LAN, WAN, internet... could be a mainframe system) These disparate result sets will be combined into a single return When returned to the requestor,...
4
6724
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my code ?? thank you Pedro Leite From Portugal ------------------------------------
2
1251
by: Matt | last post by:
I'm new to C#, so this really easy to answer for anyone that is adept at this... I'm having trouble saving data from my text boxes on a user form to my SQL database. Everything works fine while in debug mode, the data is saved and reflcted like it shoul be, but once I exit debug mode, all the changes are lost when I reopen the app in debug mode again? I saw the answer to this problem in a video but cannot find the video again? I tried...
9
5498
by: PI | last post by:
Hi Guys, I need some assistance with the following scenario please. I know this might be more of a MySQL post than a PHP one, but it is likely some developer has been here before and would be able to help out. I have some serialized data that I would like to store in a MySQL database. When viewed, the serialized data looks like this: O:4:\"cart\":4:{s:15:\"\0cart\0c_cart_id\";N;s:18:\"\0cart
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.