views:

203

answers:

2

I have a Crystal 2008 report I've created, and I want to display this report in my C# application. The user can choose to have the report get its data from one of two different databases. In my code, I'm changing the data source as follows:

    if (site == "PBG")
        reportDocument.DataSourceConnections[0].SetConnection("Server1", "MESProduction", "User", "Password");
    else
        reportDocument.DataSourceConnections[0].SetConnection("Server2", "MESProduction", "User", "Password");
    reportDocument.DataSourceConnections[0].IntegratedSecurity = false;

The report was created using the first connection information. If the user selects this database to pull data from, the report works fine. If he/she chooses the second, the report doesn't work.

Two questions: 1) Is this the correct way of setting the server/database source for the report dynamically at runtime? 2) If it is the correct way, why doesn't the report work when the user selects the second server/database? The schema of the database is exactly the same as the first.

A: 

I realise that you are after C#, but my accepted answer here should help you out http://stackoverflow.com/questions/768166/crystal-reports-configuration-tool/768266#768266

(It will obviously need tweaking slightly, as it's setting the datasource of multiple reports, but the nuts and bolts that you need are there)

Ben
@Ben - Thanks for the response. I basically changed my code to mimic yours, and I still get the same error I was getting before. If I use the connection information the report was created with, it works. If I use a different server and database, it doesn't work. The Crystal runtime tells me there is an error in the report file. However, the two databases have the exact same schema.
Randy Minder
A: 

I think what's going on is that the Command Table that is on the report already knows what connection to get to.

Try changing the .ConnectionInfo property of the CommandTable at runtime.

theo