错误:抛出了类型'System.OutOfMemoryException'的异常。
问题描述:
<%@ WebHandler Language="C#" Class="FileCS" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
public class FileCS : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
int id = int.Parse(context.Request.QueryString["id"]);
byte[] bytes;
string contentType;
string strConnString = ConfigurationManager.ConnectionStrings["Crime"].ConnectionString;
string name;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Names, Data, ContentType from tblFiles where Id=@Id";
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection = con;
con.Open();
cmd.CommandTimeout = int.MaxValue;
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
bytes = (byte[])sdr["Data"];
contentType = sdr["ContentType"].ToString();
name = sdr["Names"].ToString();
con.Close();
}
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name);
context.Response.ContentType = contentType;
context.Response.BinaryWrite(bytes);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
My above generic handler file code for reading video from datbase gives Error : Exception of type 'System.OutOfMemoryException' was thrown. how to solve this error. Please help.....
答
我认为你加载了太多数据,请检查这些
使用.net Datatable的最佳方式巨大的数据 [ ^ ]
系统内存不足异常:在数据表中选择450万条记录 [ ^ ]
I think you're loading too much data, check these
Best way to use .net Datatable with a huge data[^]
System Out of memory exception: Selecting 4.5 million records into a datatable[^]