|
|
Question : Crystal reports not displaying correct data; "Failed to load database information" error
|
|
I'm developing a website using Visual Studio 2005. It's a Crystal Report website, that I'm coding in C#. What I want to do is load a report based on an ID they pass in through the query string, and have that report pull it's data from an oracle database. After the report loads, I want to apply a selection formula to the report and display it using the Crystal Viewer object. So far, I have been unsuccessful.
1. Here is my code: _______________
// PULL PATH TO REPORT FILES FROM WEB.CONFIG private static string _reportPath = System.Configuration.ConfigurationManager.AppSettings["PathToReportFiles"].ToString();
// DATA MEMBERS protected string fileToLoad = ""; protected string strSelectionFormula = ""; protected string dbName = ""; protected string dbUser = ""; protected string dbPass = ""; protected string serverName = "";
/// /// Loads a crystal report file into the current aspx page. Accepts query string arguments: ReportID, DB, dbUsername /// and dbPassword. Only ReportID is required. /// /// /// protected void Page_Load(object sender, EventArgs e) { //get database info from query (defaults to man db, if none specified in query string) this.GetDbInfo();
//create our new report document object ReportDocument doc = new ReportDocument();
//dynamically bind the report to an RPT file through the query string try { doc.Load(Server.MapPath(_reportPath.Replace("\\\\", "\\") + this.Request.QueryString["ReportID"].ToString())); } catch { throw new SystemException("Could not load the requested report. Please contact an IT administrator."); }
doc.Refresh(); doc.SetDatabaseLogon(dbUser, dbPass, serverName, dbName);
//load selection formula from query string, or default it to empty string try { strSelectionFormula = this.Request.QueryString["SelectionFormula"].ToString(); } catch { strSelectionFormula = ""; } finally { doc.DataDefinition.RecordSelectionFormula = strSelectionFormula; }
doc.VerifyDatabase();
Viewer.ReportSource = doc; }
/// /// Dissects the query string for user supplied database information. /// protected void GetDbInfo() { // check for a user supplied database name through query string try { //create a new name value collection to collect database info from web.config NameValueCollection dataBaseInfo = new NameValueCollection();
//get database name from query string dataBaseInfo = (NameValueCollection)ConfigurationManager.GetSection("DatabaseConfigurations/" + this.Request.QueryString["Database"].ToString().ToUpper());
//gather db name, db query user, db query pass dbName = dataBaseInfo.Get("Name").ToString(); dbUser = dataBaseInfo.Get("User").ToString(); dbPass = dataBaseInfo.Get("Pass").ToString(); serverName = dataBaseInfo.Get("ServerName").ToString(); } catch { //create a new name value collection to collect database info from web.config NameValueCollection dataBaseInfo = new NameValueCollection();
//default to the MAN database dataBaseInfo = (NameValueCollection)ConfigurationManager.GetSection("DatabaseConfigurations/MAN");
//gather db name, db query user, db query pass dbName = dataBaseInfo.Get("Name").ToString(); dbUser = dataBaseInfo.Get("User").ToString(); dbPass = dataBaseInfo.Get("Pass").ToString(); serverName = dataBaseInfo.Get("ServerName").ToString(); } }
private void InitializeComponent() { this.Unload += new System.EventHandler(this.RunReport_Unload);
}
private void RunReport_Unload(object sender, EventArgs e) { //kill objects this.Viewer.Dispose(); }
2. The problem:
Basically, it loads the report with whatever data was previewed in the report during the design time. When I try to have the report update it's data, or if I even try to use the doc.VerifyDatabase() method above, I get an error. "Failed to load database information."
3. The system:
Visual Studio 2005 IDE Windows XP SP2 Database: Oracle 9i Crystal Reports XI Release 2
I believe this is some sort of version issue, or maybe this is an issue with the crystal reports objects themselves. If anyone could help, or if anyone could supply some insight into these Crystal reports objects I'm using, it would be greatly appreciated. Thank you!
|
Answer : Crystal reports not displaying correct data; "Failed to load database information" error
|
|
This may be a simplistic view of your problem, but when you open the report in Crystal, open your File menu and look at the 6th option from the top: Save Data with Report. If it's checked, then it won't refresh with current data when the users run it - it will just display what was there the last time you ran it in design mode.
For some reason, I think the default setting is for that option to be checked. Once you clear it and save the report, you should be good.
Also, if you open the File -- Options menu, and go to the Reporting tab, you can uncheck Save Data with Report and it will apply to all future reports.
|
|
|
|
|