Home All Groups Group Topic Archive Search About

DataReader Limits data returned!

Author
26 Jan 2006 1:55 PM
TY
I have a stored procedure that returns xml data (using For XML), it returns
about 9000 records. I use a datareader to write the data to a XML file.
For some reason, the datareader doesn't write all data, it seems like the
data returned has some size limit.

here is my code, my code is based on a msdn example for using getBytes were
it writes data to the stream by chunks based on the buffer size:

        '----some code here to fill in the stored procedure name and
parameters.
        Dim mydatareader As SqlDataReader
        connectionObj.Open()
        mydatareader = CommandObj.ExecuteReader

        Dim fs As FileStream
        Dim bw As BinaryWriter
        Dim bufferSize As Integer = 100
        Dim outChar(bufferSize - 1) As Char
        Dim retval As Long
        Dim startindex As Long = 0

        If mydatareader.Read Then

            fs = New FileStream("c:\test.xml", FileMode.OpenOrCreate,
FileAccess.Write)
            bw = New BinaryWriter(fs)
            retval = mydatareader.GetChars(0, startindex, outChar, 0, 100)

            ' Continue reading and writing while there are bytes beyond the
size of the buffer.
            Do While retval = bufferSize
                'bw.Write(outByte)
                bw.Write(outChar)
                bw.Flush()

                ' Reposition the start index to the end of the last buffer
and fill the buffer.
                startindex += bufferSize
                retval = mydatareader.GetChars(0, startindex, outChar, 0,
bufferSize)
            Loop

            'Write the remaining buffer.
            bw.Write(outChar, 0, CType(retval - 1, Integer))
            bw.Flush()

            ' Close the output file.
            bw.Close()
            fs.Close()
        End If
        connectionObj.Close()
        connectionObj.Dispose()
        CommandObj.Dispose()

Author
26 Jan 2006 2:53 PM
W.G. Ryan - MVP
Show quote
"TY" <tasm***@hotmail.com> wrote in message
news:2912e8f4331d4e19b4c3edf14f5c7cc0@ureader.com...
>I have a stored procedure that returns xml data (using For XML), it returns
> about 9000 records. I use a datareader to write the data to a XML file.
> For some reason, the datareader doesn't write all data, it seems like the
> data returned has some size limit.
>
> here is my code, my code is based on a msdn example for using getBytes
> were
> it writes data to the stream by chunks based on the buffer size:
>
>        '----some code here to fill in the stored procedure name and
> parameters.
>        Dim mydatareader As SqlDataReader
>        connectionObj.Open()
>        mydatareader = CommandObj.ExecuteReader
>
>        Dim fs As FileStream
>        Dim bw As BinaryWriter
>        Dim bufferSize As Integer = 100
>        Dim outChar(bufferSize - 1) As Char
>        Dim retval As Long
>        Dim startindex As Long = 0
>
>        If mydatareader.Read Then
>
>            fs = New FileStream("c:\test.xml", FileMode.OpenOrCreate,
> FileAccess.Write)
>            bw = New BinaryWriter(fs)
>            retval = mydatareader.GetChars(0, startindex, outChar, 0, 100)
>
>            ' Continue reading and writing while there are bytes beyond the
> size of the buffer.
>            Do While retval = bufferSize
>                'bw.Write(outByte)
>                bw.Write(outChar)
>                bw.Flush()
>
>                ' Reposition the start index to the end of the last buffer
> and fill the buffer.
>                startindex += bufferSize
>                retval = mydatareader.GetChars(0, startindex, outChar, 0,
> bufferSize)
>            Loop
>
>            'Write the remaining buffer.
>            bw.Write(outChar, 0, CType(retval - 1, Integer))
>            bw.Flush()
>
>            ' Close the output file.
>            bw.Close()
>            fs.Close()
>        End If
>        connectionObj.Close()
>        connectionObj.Dispose()
>        CommandObj.Dispose()
Author
26 Jan 2006 2:54 PM
W.G. Ryan - MVP
Show quote
"TY" <tasm***@hotmail.com> wrote in message
news:2912e8f4331d4e19b4c3edf14f5c7cc0@ureader.com...
>I have a stored procedure that returns xml data (using For XML), it returns
> about 9000 records. I use a datareader to write the data to a XML file.
> For some reason, the datareader doesn't write all data, it seems like the
> data returned has some size limit.
>
> here is my code, my code is based on a msdn example for using getBytes
> were
> it writes data to the stream by chunks based on the buffer size:
>
>        '----some code here to fill in the stored procedure name and
> parameters.
>        Dim mydatareader As SqlDataReader
>        connectionObj.Open()
>        mydatareader = CommandObj.ExecuteReader
>
>        Dim fs As FileStream
>        Dim bw As BinaryWriter
>        Dim bufferSize As Integer = 100
>        Dim outChar(bufferSize - 1) As Char
>        Dim retval As Long
>        Dim startindex As Long = 0
>
>        If mydatareader.Read Then
>
>            fs = New FileStream("c:\test.xml", FileMode.OpenOrCreate,
> FileAccess.Write)
>            bw = New BinaryWriter(fs)
>            retval = mydatareader.GetChars(0, startindex, outChar, 0, 100)
>
>            ' Continue reading and writing while there are bytes beyond the
> size of the buffer.
>            Do While retval = bufferSize
>                'bw.Write(outByte)
>                bw.Write(outChar)
>                bw.Flush()
>
>                ' Reposition the start index to the end of the last buffer
> and fill the buffer.
>                startindex += bufferSize
>                retval = mydatareader.GetChars(0, startindex, outChar, 0,
> bufferSize)
>            Loop
>
>            'Write the remaining buffer.
>            bw.Write(outChar, 0, CType(retval - 1, Integer))
>            bw.Flush()
>
>            ' Close the output file.
>            bw.Close()
>            fs.Close()
>        End If
>        connectionObj.Close()
>        connectionObj.Dispose()
>        CommandObj.Dispose()
--Ty, is the problem that the records aren't all getting written or that no
one record is getting written completely?

AddThis Social Bookmark Button