title: Reporting in ASP.NET
body: <p>I have an SQL Database and an ASP.NET website built to put data into the database. </p>
  
  <p>One of the project requirements is to build a system that would let the user upload a Crystal Report to the server and run it as needed. This way, the user could create a customized report (for then turning into management, customers) that wouldn't force them to go through a developer. </p>
  
  <p>I'm looking for suggestions on how to accomplish this goal.</p>
  
  <p>Currently, I'm looking for a way to redirect the database connection in the Crystal Report from the database it was developed with to the database it will eventually run on. However, There doesn't seem to be a simple way to do this. </p>
  
  <p>I'm also investigating the ReportViewer object. However, all the code I have seen involves specifying the query for the report in the code, which isn't acceptable. </p>
  
  <p>One option (which I don't like at all) is to let them write their own queries so they can copy the results into Excel. This would mean a blank textbox and information about the structure of the database. Not a good idea for multiple reasons.</p>
  
  <p>Another option is to create one report for each table (and maybe a few extras), let the user copy the data they want into Excel, and go on their merry way.</p>
  
  <p>tl;dr How do I build a flexible reporting system?</p>
  
  <p>=========================================<br>
  <strong>Continuation:</strong>    08/20/2012<br>
  I have decided to go the route of b.pell's extension methods. So far, it has gotten me closer than anything else. My code to bind to the CrystalReportViewer is below:</p>
  
  <pre><code>CrystalReportSource rs = new CrystalReportSource();
  rs.Report.FileName = Server.MapPath("ReportFiles/") + Request["reportname"];
  string connstring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
  rs.ReportDocument.ApplyCredentialsFromConnectionString(connstring);
  rs.ReportDocument.ApplyNewDatabaseName("myDBName", "mySchemaName");
  rs.ReportDocument.Refresh();
  
  CrystalReportViewer1.ReportSource = rs;
  </code></pre>
  
  <p>This comes very close to working. It works fine on my dev machine, but when I run the code on the server, it gives the following error: </p>
  
  <blockquote>
    <p>Logon failed.Error in File CrystalReport2 {5D2E82E5-783E-4DFD-A770-C8AE72A51E4E}.rpt:
    Unable to connect: incorrect log on parameters. <strong>Description:</strong> An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <strong>Exception Details:</strong> System.Runtime.InteropServices.COMException: Logon failed.Error in File CrystalReport2 {5D2E82E5-783E-4DFD-A770-C8AE72A51E4E}.rpt: Unable to connect: incorrect log on parameters. <strong>Source Error:</strong> An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</p>
  </blockquote>
  
  <p>The error is in this line in the code: </p>
  
  <blockquote>
    <p>crTable.Location = String.Format("{0}{1}", prefix, crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1))</p>
  </blockquote>
  
  <p>When I remove the call to ApplyNewDatabaseName, I am asked to enter the Server Name, the Database name, the Username and the Password or to select Integrated Security. I can't enter the Database Name or the Server Name (those fields are disabled).</p>
  
  <p>Any thoughts?</p>