这段代码给出了错误.system.outofmemory.如何避免此错误?我必须从数据库中提取1 GB的数据 [英] this code is giving error .system.outofmemory.how to avoid this error ? i have to take 1 gb of data from database

查看:125
本文介绍了这段代码给出了错误.system.outofmemory.如何避免此错误?我必须从数据库中提取1 GB的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

如果您移动
该怎么办?
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();
    }



?



?


请按照以下站点上的示例进行操作:从/到SQL读取/写入BLOB使用C#.NET DataReader的服务器 [ ^ ] .请注意此处的短语,因为它对于示例代码的正确功能非常重要: CommandBehavior.SequentialAccess .

BLOB阅读部分感兴趣的示例方法具有以下签名:
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)



问候,

— Manfred



Regards,

— Manfred


MemoryStream对象的最大容量在32位系统上为512 MB,在64位系统上为2 GB.另请参见 http://social.msdn.microsoft. com/Forums/en-US/csharpgeneral/thread/1af59645-cdef-46a9-9eb1-616661babf90 [
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[^].


这篇关于这段代码给出了错误.system.outofmemory.如何避免此错误?我必须从数据库中提取1 GB的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆