cancel
Showing results for 
Search instead for 
Did you mean: 

Why Crystal Report is connecting to old database configuration?

Former Member
0 Kudos

I am using Service Pack 1 for Crystal Reports for Eclipse 2.0.

From Eclipse, I created a Crystal Reports rpt file. The report contains tables that are coming from a Derby database. The database is located at 'C:\workspace\CrystalReportDerbySA\localdb'.

I implemented a Java standalone program that will load up the Crystal Reports rpt file and update the ConnectionInfos of the Tables to another Derby database, 'remotedb'.

However, if I deleted the database, 'C:\workspace\CrystalReportDerbySA\localdb', the report does not load up in the Java standalone program. I am getting error:

Logon Error: Database 'C:\workspace\CrystalReportDerbySA\localdb' not found.

Eventhough I have updated ConnectionInfos of the Tables to point to another Derby database, 'remotedb'.

If I restored the database, 'C:\workspace\CrystalReportDerbySA\localdb', then the report does get loaded and is executed from the other Derby database, 'remotedb' correctly.

My Crystal Reports file has one parameter.

Why do the Crystal Reports file needs to connect to the old database even though I have updated ConnectionInfos of the Tables to another database?

-Lance

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

I think I might have resolved my issues.

I need to use the replaceConnection method after I update the ConnectionInfo for a Table, updateConnectionInfo.

When I update the ConnectionInfo for a Table, notice that I commented out statement databaseController.setTableLocation.

If anyone understand what's going on, please explain.

Thanks,

	private static void updateConnectionInfo(
			DatabaseController databaseController) throws ReportSDKException {
		Tables tables = databaseController.getDatabase().getTables();

		// Set the datasource for all main report tables.
		for (int i = 0; i < tables.size(); i++) {

			ITable table = (ITable) tables.getTable(i);

			// Change connection information properties.
			IConnectionInfo connectionInfo = table.getConnectionInfo();

PropertyBag pb = new PropertyBag();
			// Set new table connection property attributes.
/*
Set new table connection property attributes.
*/
			connectionInfo.setAttributes(pb);

			connectionInfo.setUserName(null);
			connectionInfo.setPassword("password");
			connectionInfo.setKind(ConnectionInfoKind.SQL);

			table.setConnectionInfo(connectionInfo);

			//comment out line below to make it work
			//databaseController.setTableLocation(table, tables.getTable(i));
		}

		databaseController.logon(null, "password");
	}

	private static void replaceConnection(DatabaseController databaseController) throws ReportSDKException {
		ConnectionInfos connectionInfos = databaseController.getConnectionInfos(null);
		for (IConnectionInfo connectionInfo : connectionInfos) {
			PropertyBag pb = new PropertyBag();

PropertyBag pb = new PropertyBag();
			// Set new table connection property attributes.
/*
Set new table connection property attributes.
*/

			connectionInfo.setAttributes(pb);			
			
			connectionInfo.setUserName(null);
			connectionInfo.setPassword("password");
			connectionInfo.setKind(ConnectionInfoKind.SQL);		
			
			databaseController.replaceConnection(connectionInfo, connectionInfo, 
					null, DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB);
		}
		
		//databaseController.setConnectionInfos(connectionInfos);
	}

Former Member
0 Kudos

you use replaceConnection method to change your persistence data source.

replaceConnection method automatically propagates your new data source connection to all tables in the report that use old connection.

If you want to hcnage connection for particular table then you can use setTableLocation method.

Regards,

Tej

Former Member
0 Kudos

I am able to execute successful on a report that has one table and one parameter. When I add another table to the report (both when tables are linked/unlinked), the report fails.

Again, looks like the second table is causing the connection to the original database.

I used codes from this forum.

Getting exception:

Exception in thread "main" com.crystaldecisions.sdk.occa.report.lib.ReportSDKLog onException: Logon Error: Database 'C:\workspace\CrystalReportDerbySA\localdb' n ot found.---- Error code:-2147217393 Error code name:dbLogonFailed at com.crystaldecisions.sdk.occa.report.application.PrintOutputControlle r.if(Unknown Source) at com.crystaldecisions.sdk.occa.report.application.PrintOutputControlle r.export(Unknown Source) at com.crystaldecisions.sdk.occa.report.application.PrintOutputControlle r.export(Unknown Source) at Test.main(Test.java:45)

Former Member
0 Kudos

I am able to execute successful on a report that has one table and one parameter.

When I add another table to the report (both when tables are linked/unlinked), the report fails.

Again, looks like the second table is causing the connection to the original database. I used the codes from this forum.

Getting exception:

Exception in thread "main" com.crystaldecisions.sdk.occa.report.lib.ReportSDKLog onException: Logon Error: Database 'C:\workspace\CrystalReportDerbySA\localdb' n ot found.---- Error code:-2147217393 Error code name:dbLogonFailed at com.crystaldecisions.sdk.occa.report.application.PrintOutputControlle r.if(Unknown Source) at com.crystaldecisions.sdk.occa.report.application.PrintOutputControlle r.export(Unknown Source) at com.crystaldecisions.sdk.occa.report.application.PrintOutputControlle r.export(Unknown Source) at Test.main(Test.java:45)

public class Test {

	public static void main(String[] args) throws ReportSDKException,
			IOException {
		String documentPath = args[0];
		String outputFile = args[1];
		String paramName = null;
		String paramValue = null;
		if (args.length > 3) {
			paramName = args[2];
			paramValue = args[3];
		}

		ReportClientDocument reportClientDocument = createReportClientDocument(documentPath, paramName, paramValue);

		// generate PDF
		ExportOptions exportOptions = new ExportOptions();

		PDFExportFormatOptions pdfOptions = new PDFExportFormatOptions();
		exportOptions.setExportFormatType(ReportExportFormat.PDF);
		exportOptions.setFormatOptions(pdfOptions);

		PrintOutputController printOutController = reportClientDocument.getPrintOutputController();
		InputStream istream = printOutController.export(exportOptions);
		FileOutputStream fos = new FileOutputStream(outputFile);
		byte[] data = new byte[1000];
		int nRead = 0;
		while ((nRead = istream.read(data)) != -1) {
			fos.write(data, 0, nRead);
		}
		fos.close();
		istream.close();

		reportClientDocument.close();
	}

	private static ReportClientDocument createReportClientDocument(
			String documentPath, String param, String value)
			throws ReportSDKException, IOException {
		ReportClientDocument reportClientDocument = new ReportClientDocument();
		reportClientDocument.setReportAppServer(ReportClientDocument.inprocConnectionString);
		reportClientDocument.open(documentPath, OpenReportOptions._openAsReadOnly);

		// update connection info to point to the new database attributes
		updateConnectionInfo(reportClientDocument.getDatabaseController());

		// Perform the same operation against all tables in the subreport as
		// well.
		IStrings subreportNames = reportClientDocument.getSubreportController().getSubreportNames();

		// Set the datasource for all the subreports.
		for (int i = 0; i < subreportNames.size(); i++) {
			ISubreportClientDocument subreportClientDoc = reportClientDocument.getSubreportController().getSubreport(subreportNames.getString(i));

			// Switch tables for each subreport in the report using the same
			// connection information. See utility
			// method below.
			updateConnectionInfo(subreportClientDoc.getDatabaseController());
		}

		// set parameter values
		if (param != null)
			reportClientDocument.getDataDefController().getParameterFieldController().setCurrentValue("", param, value);

		return reportClientDocument;
	}

	private static void updateConnectionInfo(
			DatabaseController databaseController) throws ReportSDKException {
		Tables tables = databaseController.getDatabase().getTables();

		// Set the datasource for all main report tables.
		for (int i = 0; i < tables.size(); i++) {

			ITable table = tables.getTable(i);

			// Change connection information properties.
			IConnectionInfo connectionInfo = table.getConnectionInfo();

			// Set new table connection property attributes.
			PropertyBag pb = new PropertyBag();

			pb.put("Database DLL", "crdb_jdbc.dll");
			pb.put("Database Class Name","org.apache.derby.jdbc.EmbeddedDriver");
			pb.put("Connection URL", "jdbc:derby:remotedb");

			connectionInfo.setAttributes(pb);

			connectionInfo.setUserName(null);
			connectionInfo.setPassword("password");
			connectionInfo.setKind(ConnectionInfoKind.SQL);

			table.setConnectionInfo(connectionInfo);

			// Update old table in the report with the new table.
			databaseController.setTableLocation(tables.getTable(i), table);
		}

		databaseController.logon(null, "password");
	}	
}

Former Member
0 Kudos

I don't think you can point to different database server at runtime. You will have to open the rpt file in Crystal Reports 2008 and point to new database. Only the username/password can be set at runtime.

Former Member
0 Kudos

Please search through the forums for similar questions.

There are lots that solve this problem and many give you the code line by line.

More than likely there is a certain field somewhere or table which you are not changing correctly to the

new DB. Thus something is still trying to connect to the old DB.

.... I think.