Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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
Updated 18-Sep-12 1:48am
v3
Comments
Richard MacCutchan 18-Sep-12 8:05am    
Use less memory or buy more; those are the choices.
Manfred Rudolf Bihy 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 18-Sep-12 8:37am    
how to read blob data ???

What if you move the
C#
byte[] buffer = new byte[400000];

line, that is:

C#
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();
    }


?
 
Share this answer
 
Comments
jerinkjohn 18-Sep-12 8:31am    
not getting ...still it is showing outofmemory exception.
CPallini 18-Sep-12 8:32am    
What is the offending line?
jerinkjohn 18-Sep-12 8:35am    
den also it is showing error.
CPallini 18-Sep-12 8:38am    
Yes, I did understand, now: at what line does the error occurr?
Manfred Rudolf Bihy 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. :)
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
 
Share this answer
 
Comments
jerinkjohn 18-Sep-12 8:32am    
can you give one exaple program ???
Manfred Rudolf Bihy 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 19-Sep-12 0:59am    
thankzzz
fjdiewornncalwe 18-Sep-12 9:30am    
+5. As much for the comment as the answer itself. :)
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[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900