title: System.OutOfMemoryException on gridview
body: <p>I have a problem with my application.</p>
  
  <p>First of all, sorry about my English, I'm from Chile and I'm still learning.</p>
  
  <p>I have a method that gives an Excel with information from a db. Clients don't need to see the report on screen, they just need to download it from app.</p>
  
  <p>This method calls a stored procedure, which gives too much data (about 600 columns and 20000 rows), so, when table is assigned to a GridView, on DataBind(), throws a <code>System.OutOfMemoryException</code>.</p>
  
  <p>Is there any other way to load the GridView with data? I can't filter in query, or simplify it, because client needs every date from the report.
  I'm using Visual Studio 2010, Framework 4.0, SQL Server 2008.</p>
  
  <p>This is the method:</p>
  
  <pre><code>private void getsReport()
  {
      string reportName = "Globarl_Report_" +     User.Identity.Name + "_" + DateTime.Now.ToString("yyyyMMdd")+".xls";
      Database db = DatabaseFactory.CreateDatabase(ConfigurationManager.AppSettings["SNAT"].ToString());
      DBCommandWrapper com = db.GetSqlStringCommandWrapper("usp_con_global_report);// sp that give report.
  
      com.CommandTimeout = 360;
  
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      Page pagina = new Page();
      HtmlForm form = new HtmlForm();
      DataTable tabla = db.ExecuteDataSet(com).Tables[0]; ;
      GridView dg = new GridView();
  
      dg.EnableViewState = false;
      dg.DataSource = tabla;
      dg.DataBind();//THIS LINES THROWS EXCEPTION!!
      pagina.EnableEventValidation = false;
      pagina.DesignerInitialize();
      pagina.Controls.Add(form);
      form.Controls.Add(dg);
      pagina.RenderControl(htw);
      Response.Clear();
      Response.Buffer = true;
      Response.ContentType = "application/vnd.ms-excel";
      Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo);
      Response.Charset = "UTF-8";
      Response.ContentEncoding = Encoding.Default;
      Response.Write(sb.ToString());
      Response.End();
  }
  </code></pre>
  
  <p>thanks for your help!!</p>