Quote:
... when I read pictures from DB the Message “Out of Memory” will be shown.
Start by looking at how you are reading the data from the DB:
If you are using
SELECT * FROM ...
Then don't - list your fields so you don't return more data than you need.
Then look at what you are using to fetch the data - if your code uses a SqlDataAdapter to fill a DataTable or DataSet then that requires SQL Server to collect all the data together and transfer it as one lump - pictures can be quite large, so if there are a lot of them, then could overload your system or SQL server (and if you are working with a local DB for development, remember that means at least twice the data space is needed on the same machine). Try switching to a DataReader which returns rows on demand rather than all at once.
Then look at the number of rows you are fetching: unless you use a
WHERE
clause on your SQL you will get all of them, so it's possible that you are fetching a large number of images you don't need. Add a WHERE clause, or try returning data in pages of ten or twenty instead of all at once, that should reduce memory usage as well.
And keep an eye on the memory monitor in the debugger while you run your app - see how much it's actually using ("Out of memory" errors aren't only triggered by "real memory" running low - you also get it for scarce resources like handles, and graphics contexts, so it may be some other part of your code that is actually causing the problem. Check the exception detail in the debugger to try and find more info.