XML Import Failing on XMLDocument.Load: Unexpected end of file has occurred.
-
Hi all, I'm attempting to load an xml document from an XML column in MSSQL 2008, into an XmlDocument (see code below). Sometimes the code will break at the <b>xdoc.Load(xr)</b> line with the error "Unexpected end of file and occurred". After breaking, the XmlReader has a value of "None". While researching the problem, I saw posts that referred to a 4Kb limit on StreamReaders and figured this may be related somehow. So I cut down the size of my document (to around 4Kb) and everything worked fine. On average, the XML documents I'm importing from the database are 20Kb and thanks to validation on INSERT by MSSQL, we can assume(?) the document is well-formed. Does anyone know how to get 'large' amounts of XML from the database into my XmlDocument?
Dim xr As XmlReader = ExportAdapter.GetEditedCheckXML(chkId)
Dim xdoc As New XmlDocument
xdoc.Load(xr)Here's the GetEditedCheck fn:
Public Shared Function GetEditedCheckXML(ByVal checkId As Integer) As XmlReader Dim conn As SqlConnection = New SqlConnection(CONNECTION\_STRING) Dim comm As New SqlCommand("PS\_GetModifiedXmlByCheckId", conn) Dim adap As New SqlDataAdapter comm.CommandType = CommandType.StoredProcedure comm.Parameters.Add("@checkId", SqlDbType.Int).Value = CInt(checkId) conn.Open() Dim xml = comm.ExecuteXmlReader() xml.Read() conn.Close() Return xml End Function