imrancs
asked on
End of Stream encountered before parsing was completed.
hi experts
i want to save my ReportDocument object in file for this purpose i am using serialization concept my code is working fine for serializing the object look at the below code
Dim s As New System.IO.FileStream("C:\o bject.txt" , IO.FileMode.Create)
Dim f As New System.Runtime.Serializati on.Formatt ers.Binary .BinaryFor matter
f.Serialize(s, rptDoc)
s.Close()
but when i try to deserialize it. it generates error "End of Stream encountered before parsing was completed." look at the below code and tell me where i am wrong
Dim s = New System.IO.FileStream("C:\o bject.txt" , IO.FileMode.Open)
Dim f As System.Runtime.Serializati on.Formatt ers.Binary .BinaryFor matter = New System.Runtime.Serializati on.Formatt ers.Binary .BinaryFor matter
rptDoc = CType(f.Deserialize(s), ReportDocument)
s.close()
thanks,
ahmad
i want to save my ReportDocument object in file for this purpose i am using serialization concept my code is working fine for serializing the object look at the below code
Dim s As New System.IO.FileStream("C:\o
Dim f As New System.Runtime.Serializati
f.Serialize(s, rptDoc)
s.Close()
but when i try to deserialize it. it generates error "End of Stream encountered before parsing was completed." look at the below code and tell me where i am wrong
Dim s = New System.IO.FileStream("C:\o
Dim f As System.Runtime.Serializati
rptDoc = CType(f.Deserialize(s), ReportDocument)
s.close()
thanks,
ahmad
ASKER
Hi Bob
i creates a new ReportDocument object before deserialize time. look at the below code
Dim rptDoc as new ReportDocument
Dim s = New System.IO.FileStream("C:\o bject.txt" , IO.FileMode.Open)
Dim f As System.Runtime.Serializati on.Formatt ers.Binary .BinaryFor matter = New System.Runtime.Serializati on.Formatt ers.Binary .BinaryFor matter
rptDoc = CType(f.Deserialize(s), ReportDocument)
s.close()
Thanks,
Ahmad
i creates a new ReportDocument object before deserialize time. look at the below code
Dim rptDoc as new ReportDocument
Dim s = New System.IO.FileStream("C:\o
Dim f As System.Runtime.Serializati
rptDoc = CType(f.Deserialize(s), ReportDocument)
s.close()
Thanks,
Ahmad
Did you compare the size of the file, with the expected size of the serializated text, to see if any extra characters are added to the text file, that would confuse the deserializer?
Bob
Bob
ASKER
Bob
How can compare it and how can i check file for extra characters.
thanks,
ahmad
How can compare it and how can i check file for extra characters.
thanks,
ahmad
ASKER
Bob
I have resolved this problem but now i am gettin following error at deserialize time.
Exception has been thrown by the target of an invocation.
have any idea why i am getting.
thanks,
ahmad
I have resolved this problem but now i am gettin following error at deserialize time.
Exception has been thrown by the target of an invocation.
have any idea why i am getting.
thanks,
ahmad
First, what was your solution? What was the problem?
Bob
Bob
ASKER
Hi Bob
I was saving object in txt file when i saved it in doc or dat file then it worked fine. Now i am getting error
Exception has been thrown by the target of an invocation.
inner exception is
RAS is not running
RAS server is very expensive so we cant use it. can i store my object some other and better ways.
its very urgent
thanks,
ahmad
I was saving object in txt file when i saved it in doc or dat file then it worked fine. Now i am getting error
Exception has been thrown by the target of an invocation.
inner exception is
RAS is not running
RAS server is very expensive so we cant use it. can i store my object some other and better ways.
its very urgent
thanks,
ahmad
Are you looking for somewhere besides a database, like SQL Server or Oracle?
Bob
Bob
ASKER
Hi Bob
I am using SQL Server and i have already try to store my object in database in binary form. but when i try to use it again then it generates error at converting it to reportdocument object. problem in casting and also deserializing.
you have any idea where i am wrong.
thanks,
ahmad
I am using SQL Server and i have already try to store my object in database in binary form. but when i try to use it again then it generates error at converting it to reportdocument object. problem in casting and also deserializing.
you have any idea where i am wrong.
thanks,
ahmad
Here is a class for working with SQL Server and BLOBs:
Imports System.Data.SqlClient
Public Class SqlServerBlobs
Private m_connectString As String = String.Empty
Private m_builderSQL As SqlCommandBuilder
Private m_adapterDatabase As SqlDataAdapter
Private m_dataResult As DataTable
Public Sub New(ByVal connectString As String)
' Test for invalid parameters.
If connectString.Length = 0 Then
Throw New ArgumentNullException("Con nection string is empty")
End If
m_connectString = connectString
End Sub 'New(connect)
Private Sub GetColumnData(ByVal table As String, ByVal column As String)
' Test for invalid parameters.
If table.Length = 0 Then
Throw New ArgumentNullException("Tab le name is empty")
End If
If column.Length = 0 Then
Throw New ArgumentNullException("Col umn name is empty")
End If
' Initialize the Select query text
' Example:
' Select image_data
' From ImageLibrary_Table
Dim commandText As String = String.Format("Select {0} From {1}", column, table)
' Create an adapter to perform the Get operation.
m_adapterDatabase = New SqlDataAdapter(commandText , m_connectString)
m_adapterDatabase.MissingS chemaActio n = MissingSchemaAction.AddWit hKey
' Generate InsertCommand and UpdateCommand from the SelectCommand.
m_builderSQL = New SqlCommandBuilder(m_adapte rDatabase)
' Create a new DataSet for the column data.
m_dataResult = New DataTable
' Get the column data.
m_adapterDatabase.Fill(m_d ataResult)
End Sub
Public Sub InsertBlobData(ByVal table As String, _
ByVal column As String, ByVal data As Byte())
' Open the table, and get a DataSet representing the
' Blob column.
Me.GetColumnData(table, column)
' Insert the data.
Dim newRow As DataRow = m_dataResult.NewRow()
newRow(column) = data
m_dataResult.Rows.Add(newR ow)
' Write the new data to the database.
m_adapterDatabase.Update(m _dataResul t)
End Sub
Public Function ReadBlobData(ByVal table As String, ByVal column As String, _
ByVal filter As String) As Byte()
' Open the table, and get a DataSet representing the
' Blob column.
Me.GetColumnData(table, "*")
' Find the right record based on the filter expression.
Dim rowFind As DataRow() = m_dataResult.Select(filter )
If rowFind.Length > 0 Then
' The data from the field is a byte array, so an implicit conversion occurs here.
Return rowFind(0)(column)
End If
End Function
End Class
Bob
Imports System.Data.SqlClient
Public Class SqlServerBlobs
Private m_connectString As String = String.Empty
Private m_builderSQL As SqlCommandBuilder
Private m_adapterDatabase As SqlDataAdapter
Private m_dataResult As DataTable
Public Sub New(ByVal connectString As String)
' Test for invalid parameters.
If connectString.Length = 0 Then
Throw New ArgumentNullException("Con
End If
m_connectString = connectString
End Sub 'New(connect)
Private Sub GetColumnData(ByVal table As String, ByVal column As String)
' Test for invalid parameters.
If table.Length = 0 Then
Throw New ArgumentNullException("Tab
End If
If column.Length = 0 Then
Throw New ArgumentNullException("Col
End If
' Initialize the Select query text
' Example:
' Select image_data
' From ImageLibrary_Table
Dim commandText As String = String.Format("Select {0} From {1}", column, table)
' Create an adapter to perform the Get operation.
m_adapterDatabase = New SqlDataAdapter(commandText
m_adapterDatabase.MissingS
' Generate InsertCommand and UpdateCommand from the SelectCommand.
m_builderSQL = New SqlCommandBuilder(m_adapte
' Create a new DataSet for the column data.
m_dataResult = New DataTable
' Get the column data.
m_adapterDatabase.Fill(m_d
End Sub
Public Sub InsertBlobData(ByVal table As String, _
ByVal column As String, ByVal data As Byte())
' Open the table, and get a DataSet representing the
' Blob column.
Me.GetColumnData(table, column)
' Insert the data.
Dim newRow As DataRow = m_dataResult.NewRow()
newRow(column) = data
m_dataResult.Rows.Add(newR
' Write the new data to the database.
m_adapterDatabase.Update(m
End Sub
Public Function ReadBlobData(ByVal table As String, ByVal column As String, _
ByVal filter As String) As Byte()
' Open the table, and get a DataSet representing the
' Blob column.
Me.GetColumnData(table, "*")
' Find the right record based on the filter expression.
Dim rowFind As DataRow() = m_dataResult.Select(filter
If rowFind.Length > 0 Then
' The data from the field is a byte array, so an implicit conversion occurs here.
Return rowFind(0)(column)
End If
End Function
End Class
Bob
ASKER
Hi Bob
My actual problem is not storing object in database. actually my problem is that i am storing my reportdocument object in binary form. it works fine but when again i try to use it and convert it from binary to reportdocument it prompts error binary can not be converted in reportdocument or some other. look at below
rpt = CType(arr, ReportDocument)
error:"F:\Serialization\Er icMoreau\D emoCode\Fo rm1.vb(353 ): Value of type '1-dimensional array of Byte' cannot be converted to 'CrystalDecisions.CrystalR eports.Eng ine.Report Document'. "
thanks,
ahmad
My actual problem is not storing object in database. actually my problem is that i am storing my reportdocument object in binary form. it works fine but when again i try to use it and convert it from binary to reportdocument it prompts error binary can not be converted in reportdocument or some other. look at below
rpt = CType(arr, ReportDocument)
error:"F:\Serialization\Er
thanks,
ahmad
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did the ReportDocument change between the time that you serialized it, and when you deserialized it?
Bob