title: How do I change a Crystal Report's ODBC database connection at runtime?
body: <p>I have a report made with Crystal Reports 2008 that I need to deploy a production system which means that I need to be able to change the database connection at runtime.  The database is PostgreSQL 8.3.0 and the connection I use for creating the initial report is an ODBC connection.</p>
  
  <p>I have found various ways to change the database connection including the following:</p>
  
  <pre><code>reportDoc.Load(report);
  reportDoc.DataSourceConnections[0].SetConnection("server", "database", "user", "pwd");
  reportDoc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, path);
  </code></pre>
  
  <p>However, this always fails with the following error message.</p>
  
  <blockquote>
    <p>Failed to open the connection.</p>
  </blockquote>
  
  <p>I have validated the connection parameters by successfully connecting to the database with pgAdmin III so I know the connection parameters are correct.  In addition, if I remove the SetConnection(...) line so the code looks like this:</p>
  
  <pre><code>reportDoc.Load(report);
  reportDoc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, path);
  </code></pre>
  
  <p>then the report runs fine using the connection parameters that are stored in the report.  Is it possible that this method does not work for ODBC connections?</p>
  
  <p>How do I change a Crystal Report's ODBC database connection at runtime?</p>