Setting Database Credentials

If you have tried to use some of the code samples thus far, you might have found that your reports were failing to run when scheduled. One of the causes of this is a lack of database credentials. Keep in mind that Crystal Reports stores all the connection information for the database inside the report except the password. Therefore, this needs to be set at runtime. The easiest way to do this is to type it in manually in the Crystal Management Console and save it with the InfoObject (shown in Figure 35.4). However, sometimes there are many reports and this manual step becomes unrealistic. In this case, the reports credentials can be set programmatically.

Figure 35.4. Setting database credentials through the Crystal Management Console.


To set a reports credentials, call the getReportLogons method of the IReport interface. This returns a Crystal Enterprise collection interface called ISDKList. The reason there is a collection of report credentials is that some reports point to multiple data sources that each have their own respective credentials. These reports are rare though, so assume a collection of only one element. Calling the get method returns an IReportLogon interface. Here you can call the setUserName and setPassword methods as shown in the following code:

IInfoObjects results = iStore.query("SELECT * FROM CI_INFOOBJECTS WHERE " +

 "SI_NAME=World Sales Report AND SI_INSTANCE=0");

IInfoObject infoObject = (IInfoObject) results.get(0);

IReport report = (IReport) infoObject;

ISDKList list = report.getReportLogons();

IReportLogon logon = (IReportLogon) list.get(0);



ISchedulingInfo sched = infoObject.getSchedulingInfo();


There are other methods available from the IReportLogon method such as setCustomServerName and setCustomerDatabaseName that enable you to point the report at a different database and server at schedule-time if required.

Special Edition Using Crystal Reports 10
Special Edition Using Crystal Reports 10
ISBN: 0789731134
EAN: 2147483647
Year: 2003
Pages: 341
Simiral book on Amazon © 2008-2017.
If you may any questions please contact us: