Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

Changing server/database of a report in code

$
0
0

Hi,

 

I'm using ODBC to connect my ReportDocument to a database. Let's say I have two ODBC datasources: ODBCTest for the test database and ODBCProd for production. I'm using a report that was designed using ODBCTest.

 

My code knows which ODBC to use (ODBCTest, ODBCProd or whatever (customers can create their own ODBC datasources). How can I set in code the target ODBC data source for my report?

I tried ReportDocument.SetDatabaseLogin(user, password, server, database, ignoreCase).

It sounded promising as one can specify the server and/or database here. But it didn't work, so I checked the implementation using reflection (dotPeek). To my big surprise it seems that this method cannot be used to set the server/database for the ReportDocument, instead these values are only used to check whether they match the server/database the report uses and only then apply the user/password:

 

ReportDocument.SetDatabaseLogin internally calls SetTableLogon which does this:

if (string.Compare(logOnInfo.ConnectionInfo.ServerName, server, true) == 0 && string.Compare(logOnInfo.ConnectionInfo.DatabaseName, database, ignoreCase) == 0)

{

  logOnInfo.ConnectionInfo.UserID = user;

  logOnInfo.ConnectionInfo.Password = password;

  table.ApplyLogOnInfo(logOnInfo);

  [...]

}

 

So how do I set which ODBC datasource a ReportDocument should use at runtime?

 

Thanks,

Markus


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>