Click here to Skip to main content
11,496,012 members (66,311 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
if (videoData.Read())
    {
        byte[] a = (byte[])videoData[0];
        using (var videoStream = new MemoryStream(a))
        {
            Response.BufferOutput = false;
            byte[] buffer = new byte[400000];
            int bytesRead = 0;
            while ((bytesRead = videoStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                Response.OutputStream.Write(buffer, 0, bytesRead);
            }
        }
        videoData.Close();
    }
Posted 18-Sep-12 1:42am
Edited 18-Sep-12 2:48am
RyanDev156.7K
v3
Comments
Richard MacCutchan at 18-Sep-12 8:05am
   
Use less memory or buy more; those are the choices.
Manfred R. Bihy at 18-Sep-12 8:34am
   
The problem with your code is that you seem to be reading the whole BLOB at one time. This will most certainly exahaust your memory quickly if the BLOBs are very large or if there are many requests at one time. Since I can't see the code you're using to open the database I suggest you see my solution and try accessing the data in a sequential manner only reading smaller chunks of data and writing that to the response stream.
jerinkjohn at 18-Sep-12 8:37am
   
how to read blob data ???
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What if you move the
byte[] buffer = new byte[400000];
line, that is:

if (videoData.Read())
    {
        byte[] a = (byte[])videoData[0];
        byte[] buffer = new byte[400000]; // <--- moved here
        using (var videoStream = new MemoryStream(a))
        {
            Response.BufferOutput = false;
            int bytesRead = 0;
            while ((bytesRead = videoStream.Read(buffer, 0, buffer.Length)) &gt; 0)
            {
                Response.OutputStream.Write(buffer, 0, bytesRead);
            }
        }
        videoData.Close();
    }

?
  Permalink  
Comments
jerinkjohn at 18-Sep-12 8:31am
   
not getting ...still it is showing outofmemory exception.
CPallini at 18-Sep-12 8:32am
   
What is the offending line?
jerinkjohn at 18-Sep-12 8:35am
   
den also it is showing error.
CPallini at 18-Sep-12 8:38am
   
Yes, I did understand, now: at what line does the error occurr?
Manfred R. Bihy at 18-Sep-12 8:39am
   
Hi CPallini!
The problem OP is encountering lies in the fact that he's trying to read in the whole BLOB at once. There is a method where one can use CommandBehavior.SequentialAccess to read the BLOB chunk wise. :)
CPallini at 18-Sep-12 8:51am
   
Ah OK, it is the internal memory allocation of the VideoData reader. I supposed the OP was using too much memory prior of the garbage collector intervention.
I didn't know the DataReader was a bit 'dumb'.
jerinkjohn at 19-Sep-12 0:59am
   
thnkzzzz........
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please follow the sample at this site: Read / Write BLOBs from / to SQL Server using C# .NET DataReader [^]. Be on the lookout for this here phrase, as it's very essential to the correct function of the sample code: CommandBehavior.SequentialAccess.

The sample method of interest to you for the BLOB reading part has this signature:
public void GetEmployee(string plastName,string pfirstName)

Regards,

— Manfred
  Permalink  
Comments
jerinkjohn at 18-Sep-12 8:32am
   
can you give one exaple program ???
Manfred R. Bihy at 18-Sep-12 8:37am
   
You're kidding me! X|
1. The site contains a complete sample
2. There's even a download link at the top of that page where you can get the complete codes.
I ask you only once: "What more do you need?"
jerinkjohn at 19-Sep-12 0:59am
   
thankzzz
Marcus Kramer at 18-Sep-12 9:30am
   
+5. As much for the comment as the answer itself. :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

The maximum capacity of a MemoryStream object is 512 MB on 32bit systems and 2 GB on 64bit systems, resp. See also http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/1af59645-cdef-46a9-9eb1-616661babf90[^].
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 CHill60 318
2 RyanDev 230
3 Sascha Lefèvre 205
4 OriginalGriff 186
0 Sergey Alexandrovich Kryukov 10,372
1 OriginalGriff 8,871
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100