• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 77
  • Last Modified:

Memory out exception when using sqldatareader for extracting bytes

Hello,
I have an varbinary column which stores bytes for an image.
The query is throwing an exception Out of memory .
I am using a Stored Procedure to get the query result.
This is the code:
  Public Sub Populate(ByVal Command As SqlCommand)
            'Accept command as string and fill the datatable with the result of sql query
            
            Dim dt = New DataTable
            Dim SQLdr As SqlDataReader
        Try

            SQLdr = Command.ExecuteReader(CommandBehavior.SequentialAccess)
            dt.BeginLoadData()
            dt.Load(SQLdr)
            dt.EndLoadData()

            Command.Connection.Close()
            Application.DoEvents()
            Command.Dispose()
            Data_Table = dt

        Catch MyException As SqlException
            MessageBox.Show("Stored procedure Error: MySQL code: " &
            MyException.Number & "  " &
            MyException.Message)
            End Try
        End Sub

Open in new window


Any suggestions are appreciated as I have been struggling with this for quite a while.

Thanks
0
RIAS
Asked:
RIAS
  • 2
1 Solution
 
louisfrCommented:
Are you retrieving the whole table? How much data does the table contain?
0
 
Máté FarkasDatabase Developer and AdministratorCommented:
There 2 possible reasons:
1. Your table is too big (too many rows and/or too many columns)
2. Varbinary column is too big and DataTable cannot fetch all rows from the table.

My recommendations:
- Don't fetch all rows into a DataTable because it is very memory consuming operation
- Implement data processing in loop instead and fetch records of that table row by row (with DataReader)
1
 
RIASAuthor Commented:
Thanks.There is column of pictures saved as bytes , it has around 300 photos.
Thanks
0
 
Máté FarkasDatabase Developer and AdministratorCommented:
There is no good solution for that problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now