I'm back to doing Crystal Reports for one of my long-term consulting projects... ick. For the project I work on there's two databases: a test database and the live database, the obvious difference being that the test database has test data and the live database is currently in use with live data. Both have identical schemas.
Anywho, when creating a Crystal Report through VS.NET you have to specify the datasource that you want to use for the report, which can be done through an ADO DataSet or, as commonly the case in this particular project, through a view, table, or stored procedure on the actual database. Since I am developing on the test database, I've always connected to the test database when crafting my Crystal Reports. In my ASP.NET page I programmatically display my Crystal Report by first setting the logon information using the code Eric Landes shares in his article titled Automagically Display Crystal Parameters. Specifically, in the ApplyInfo() I set the DatabaseName and other related server properties to the current database I am using, which is spelled out in the application's Web.config file. On the development server the Web.config file indicates to use the test database; on the production server, it says to use the live database.
My assumption was that setting this logon info through this manner would have the correct datasource be called from the Crystal Report when viewed on an ASP.NET page. That is, if I created the CR referencing the test database, but the CR was on the live site, it would use the live site's underlying data. Today, when pushing up my latest batch of reports to the live server, I found out that assumption was incorrect. Meh. The result - the reports on the live site were showing data from the test database. All of a sudden end users were seeing information about people named Mr. Test and Mr. Test 2. Eep.
My workaround was to augment the ApplyInfo() method, adding the following line in the For Each oCRTable In oCRTables loop:
oCRTable.Location = oCRConnectionInfo.DatabaseName & ".dbo." & oCRTable.Location.Substring(oCRTable.Location.LastIndexOf(".") + 1)
This modifies the datasource SQL used from something like testDB.dbo.TableName to realDB.dbo.TableName, where realDB is the database name specified in the Web.config file (so its using the test database for its datasource when working on the development server and the live database for its datasource when viewing a report on the live site).
Hope this saves someone else the headache I experienced! :-)