title: MVC 4 Reporting with Entity Framework
body: <p>I'm using MVC4 and Entity Framework in order to develop an intranet web app and I have to create reports which can be dowloaded by the users. In fact, I have 2 report templates (.rdlc files). One of them is a generic template which will be copied and modified for the next templates. That's what I did with my "PersonReport" template : copied and modified from the generic. </p>
  
  <p>My problem is that with the genereic template (and the code below), everything's fine. However, when I'm using my personalized template, it doest not work. I tried to debug my code and I found where is the issue (when I'm using the .Render() to specifiy the format). There is my error message : </p>
  
  <pre><code>An error occurred during local report processing.
  </code></pre>
  
  <p>Here is my action : </p>
  
  <pre><code>public ActionResult PersonReport()
  {
  
      ReportViewer personReportViewer = new ReportViewer();
  
      //Parameters
  
      ReportParameter[] reportParameters = new ReportParameter[3];
      reportParameters[0] = new ReportParameter("Title", "Test", true);
      reportParameters[1] = new ReportParameter("Address", "Avenue de Tervuren,  268", true);
      reportParameters[2] = new ReportParameter("PostalCode", "B-1150 Brussels", true);
  
      //Report Template
  
      personReportViewer.ProcessingMode = ProcessingMode.Local;
      personReportViewer.LocalReport.ReportPath = HttpContext.Server.MapPath("..") + "\\Reporting\\Templates\\" + "AllPersonsReport.rdlc";
  
      //Source
  
      DataSet ds = BuSIMaterial.Utils.Services.ExecuteStoredProcedure(db, "GetAllPersons", null);
  
      ReportDataSource dataSource = new ReportDataSource("personDataSource", ds.Tables[0]);
      personReportViewer.LocalReport.DataSources.Clear();
      personReportViewer.LocalReport.DataSources.Add(dataSource);
  
      //Report type
  
      personReportViewer.LocalReport.SetParameters(reportParameters);
      byte[] byteArray = personReportViewer.LocalReport.Render("PDF"); //Here's the failure
  
      //Downloading
  
      Response.ClearHeaders();
      Response.AddHeader("Content-Disposition", "attachment; Filename=\"" + DateTime.Now + "_Title_.pdf" + "\"");
      Response.AddHeader("Content-Transfer-Encoding", "Binary");
      Response.BinaryWrite((byte[])byteArray);
      Response.Flush();
      Response.End();
  
      return RedirectToAction("Index");
  }
  </code></pre>
  
  <p>And my method to create a DataSet from a simple select * stored procedure : </p>
  
  <pre><code>public static DataSet ExecuteStoredProcedure(ObjectContext db,
                                       string storedProcedureName,
                                       IEnumerable&lt;SqlParameter&gt; parameters)
  {
      var connectionString =
          ((EntityConnection)db.Connection).StoreConnection.ConnectionString;
  
      var ds = new DataSet();
  
      using (var conn = new SqlConnection(connectionString))
      {
          using (var cmd = conn.CreateCommand())
          {
              cmd.CommandText = storedProcedureName;
              cmd.CommandType = CommandType.StoredProcedure;
  
              if (parameters != null)
              {
                  foreach (var parameter in parameters)
                  {
                      cmd.Parameters.Add(parameter);
                  }
              }
  
              using (var adapter = new SqlDataAdapter(cmd))
              {
                  adapter.Fill(ds);
              }
          }
      }
  
      return ds;
  }
  </code></pre>
  
  <p><strong>UPDATE</strong> : I wanted to check if my DataSet was filled and it isn't. Could it be the problem?</p>