views:

125

answers:

3

I created a crystal report using test a DB. I run the report using .NET ReportDocument class. Everything works fine until I connect to the test DB.

When same report is pointed to UAT DB (all required DB objects are available in UAT too), I am getting error. To fix this, I have to change the server name to UAT DB manually in the RPT file.

How to fix this?

A: 

Using push reports should solve your issue. You can set up the report to accept a strongly-typed ADO.NET Dataset, and supply that dataset at runtime.

Jeremy Frey
No, I am not using any ADO.NET DataSet. The report talks to DB objects firectly. Only thing I have to do is, send the connection details during runtime.
Kaz
AFAIK, you can't. The report maintains its own database settings that are set up at design time, and can't be changed at runtime.
Jeremy Frey
A: 

Isn't that how it's supposed to work? It has to know to what DB it's connecting?

Maybe I'm missing something but it sounds like you just needed to get the connection right.

John at CashCommons
Crystal reports can operate in two basic modes: push or pull. Most reports I've seen built use pull, which stores the connection data within the report class. It's nice for when the report has to live on its own, but inside the scope of a larger application, it's a PITA, because the report data source has to be manually changed whenever the code moves to a different server (i.e. dev -> test -> production). Push reports let the report accept data from an outside source, which can include an ADO.NET dataset, which centralizes the details of the connection.
Jeremy Frey
+1  A: 

A solution is to create a system DSN (ODBC) for connecting to your target database. You can then switch the ODBC to whichever database you want (local,test,stage etc). Also, if you ensure an ODBC connection of the same name is available on all your servers, moving the report from dev->test->stage->production should be easy.

Tundey