mscorlib.dll中出现“System.OutOfMemoryException”类型的异常,但未在用户代码中处理

时间:2015-03-26 19:21:28

标签: c#-4.0 file-upload video-streaming streamreader

我从管理面板上传较大的视频文件,例如1 GB大小,但每当我尝试上传较大的文件时,我都会收到“'System.OutOfMemoryException'”错误。 这是我的代码:

 protected void btnUpload_Click(object sender, EventArgs e)
        {
            using (BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream))
            {
                byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length);
                string _connString = ConfigurationManager.AppSettings["connString"];
                int id=1;
                using (SqlConnection con = new SqlConnection(_connString))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandText = "update ref_Accueil set nm_Video=@nm_Video where id_Page=@id_Page";
                        cmd.Parameters.AddWithValue("@id_Page", id);
                        cmd.Parameters.AddWithValue("@nm_Video", bytes);
                        cmd.Connection = con;
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                }
            }
            Response.Redirect(Request.Url.AbsoluteUri);
        }

我正在为我的视频使用Flow Player。

以下是我的web.config中的代码

<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
  </system.web>
  <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="3000000000" />
      </requestFiltering>
   </security>
</system.webServer>

当我尝试从数据库中获取更大的文件时我也在system.dll上遇到此错误,这是代码的另一部分:

public void ProcessRequest(HttpContext context)
        {
            int id = int.Parse(context.Request.QueryString["id_Page"]);
            byte[] bytes;
            string contentType;
            string _connString = ConfigurationManager.AppSettings["connString"];
            string name;
            using (SqlConnection con = new SqlConnection(_connString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "select id_Page, nm_Video from ref_Accueil where id_Page=@id_Page";
                    cmd.Parameters.AddWithValue("@id_Page", id);
                    cmd.Connection = con;
                    con.Open();
                    SqlDataReader sdr = cmd.ExecuteReader();
                    sdr.Read();
                    bytes = (byte[])sdr["nm_Video"];
                    //contentType = sdr["ContentType"].ToString();
                    //name = sdr["Name"].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;
            }
        }
绑定时

private void BindGrid()
            {
                string _connString = ConfigurationManager.AppSettings["connString"];
                using (SqlConnection con = new SqlConnection(_connString))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandText = "select id_Page, nm_Video from ref_Accueil";
                        cmd.Connection = con;
                        con.Open();
                        DataList1.DataSource = cmd.ExecuteReader();
                        DataList1.DataBind();
                        con.Close();
                    }
                }
            }

0 个答案:

没有答案