serialize to SQL Server Blob instead of XML serialize

G

Gordz

I've been experiencing problems on some computers with XML Serialization. On
some computers the files do not get created on the web server's hard drive
and it's been driving me nuts trying to figure it out.

I store navigation history and application state in object collections and
save this upon application exit by doing an XML.Serialize.

I'd like to serialize directly to SQL Server instead. Can I create a stream
object to be used by SQL Server with serialization?

Thanks
 
J

John Oakes

Yeah, this is the basics (DT is just an object I'm taking from session and
serializing):

Dim ms As New MemoryStream
ms = SerializeDT(CType(Session("DT"), DTProcess))
Dim da() As Byte
da = ms.ToArray
cmd.Parameters("@DesktopData").Value = da
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()

Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
MemoryStream
Dim ms As New MemoryStream
Dim formatter As New BinaryFormatter
formatter.Serialize(ms, DTSource)
ms.Position = 0
Return ms
End Function

-John Oakes
 
G

Gordz

thanks John.

I've never used binary objects in SQL before.

Where exactly is your data "@DesktopData" stored in the database? Do you
have a field already defined?

Cheers,

Gord

Yeah, this is the basics (DT is just an object I'm taking from session and
serializing):

Dim ms As New MemoryStream
ms = SerializeDT(CType(Session("DT"), DTProcess))
Dim da() As Byte
da = ms.ToArray
cmd.Parameters("@DesktopData").Value = da
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()

Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
MemoryStream
Dim ms As New MemoryStream
Dim formatter As New BinaryFormatter
formatter.Serialize(ms, DTSource)
ms.Position = 0
Return ms
End Function

-John Oakes
 
J

John Oakes

Yes, I have a field defined. The datatype is image, which is
variable-length binary data from 0 through 231-1 (2,147,483,647) bytes.

-John Oakes
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top