cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Crystal Report data source at runtime

Former Member
0 Kudos

In advance, I've read all of the posts on here about dynamically changing the data source for your report at runtime and none of it seems to work.

I developed a report against my development database using an MySQL ODBC connection. At runtime I want to pull the data from the production database. I've tried clearing the DataSourceConnections. I've tried the SetDatabaseLogon as well as Table.LogOnInfo, Table.ApplyLogOnInfo, SetConnection, everything.

I am using the pull method for getting the data, so CR has entire control over the mechanism used to fetch the data.

But when I am setting some other data source I am greeted with a logon screen for the database, I i check use itegrated security then it says logon failed and if I uncheck use integrated security checkbox then it shows unable to load report and an exception is thrown

Anyone have any ideas? I'm using Visual Studio 2010 and Crystal Reports 2011 developer edition.Apart from this my Database is in mysql and I am binding report with the MySQL Procedure.

Note: Both these database just differ in name, Infact they are same database just I have changed the name, so the procedure and the fields are same.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

First question would be; can you change the datasource in the designer? This will be a good test as if you can not, you will certainly not be able to do it at runtime.

Next, since you are using ODBC, you have to be careful of the "bitness" of the datasource. E.g.; if your development datasource is 32 bit and you compile the app as 32 bit, it will work just fine. Now, if your production ODBC is created as 64 bit ODBC datasource, there is no way a 32 bit app will read it.

Given that all of the above checks out, see if you can run the vbnet_win_dbengine sample app with your report and DB parameters. The sample app can be downloaded from here:

Crystal Reports for .NET SDK Samples - Business Intelligence (BusinessObjects) - SCN Wiki

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Former Member
0 Kudos

So if ODBC doesn't allow me to change the data source, can't it be done in some other way without mingling with each and every report.

BDW I am able to change the data-source at designer mode,

Currently the connection string being used is

private readonly ConnectionInfo crConnectionInfo = new ConnectionInfo

        {

            DatabaseName = "DB NAME",

            IntegratedSecurity = true,

            Password = "admin",

            ServerName = "localhost",

            UserID = "root"

        };

I just want it to read from same copy of database place at some other location so the connection string will be modified as

private readonly ConnectionInfo crConnectionInfo = new ConnectionInfo

        {

            DatabaseName = "Same copy of database record may change but structure will be same",

            IntegratedSecurity = true,

            Password = "admin",

            ServerName = "IP address of the machine",

            UserID = "root"

        };

former_member183750
Active Contributor
0 Kudos

One thing; if IntegratedSecurity = true, why are you passing in log on info such as pwd?

Maybe checking this doc will help.

- Ludek

Former Member
0 Kudos

I was just using it .... but it doesn't work either way.....

The issue here is that I made a ODBC connection and on that I set connection to a database and designed my reports on that database.

Now I have made a copy of same database and changed its name.... every thing else is same i.e data, procedure and table.

Now I want the reports to be generated from this new database.

nutshell reports were designed on databaseVer1 now same db has been copied and named as databaseVer2, system is not able to generate the reports from databaseVer2

former_member183750
Active Contributor
0 Kudos

Well, nutshell is fine, but showing the code you did just confuses the issue and now I have to ask;

Is this a Trusted Data source? If it is, you should not need any code. Just enable "Verify on 1st refresh" option on the report.

If the DS is not trusted, you have to supply the correct login parameters. And enabling the "Verify on 1st refresh" option on the report will also be a good idea.

Another test may be to create a completely new ODBC DS with then new db name and point the report at that in your code. What happens in this case?

- Ludek

Former Member
0 Kudos

okay tried both of above... none is working... Is there any way to change the query which is made automatically by crystal reports while using pull method, May be changing the database name in the query could help me!!!

Till now I have tried with following

Made a new DSN,

Checked verify at every point and also checked by unchecking above field,

removed the default data source connection of crystal report

and reset logon information of table... but none of above worked.

former_member183750
Active Contributor
0 Kudos

Unfortunately, there is no way to change the SQL query. What you could try to do though, is create a dataset and pass that to the report. You then do not need any db logon information for the report as that is taken care of by you when you create the DS.

- Ludek

Answers (0)