Print Page | Close Window

change database location for a report programmatic

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2022
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17026
Printed Date: 21 Apr 2025 at 2:47am


Topic: change database location for a report programmatic
Posted By: RazorT4x
Subject: change database location for a report programmatic
Date Posted: 13 Jul 2012 at 5:52am
Hi all, Good day to every one! This is my first post here!
So, I have this crystal report (CR version 9) and I want to change its database location programmatically. I am doing something right now, but there is a problem. Perhaps my code would explain better.


  private void MainReport_Load(object sender, EventArgs e)
    {
        var constr = string.Empty;
        constr = Application.StartupPath;
        if (Generate.bForProjects)
            constr = Path.Combine(constr, @"Reports\Projects.rpt");
        else
            constr = Path.Combine(constr, @"Reports\Other.rpt");

        var myConInfo = new CrystalDecisions.Shared.TableLogOnInfo();
        reportDocument1.Load(constr);
        myConInfo.ConnectionInfo.DatabaseName = "ProjectData.mdb";
        myConInfo.ConnectionInfo.ServerName = Application.StartupPath + @"\Data\ProjectData.mdb";
        myConInfo.ConnectionInfo.Password = "";
        myConInfo.ConnectionInfo.UserID = "";
        reportDocument1.Database.Tables[0].ApplyLogOnInfo(myConInfo);

        reportDocument1.Refresh();

        crystalReportViewer1.ReportSource = reportDocument1;
        crystalReportViewer1.Width = this.Width - 50;
        crystalReportViewer1.Height = this.Height - 100;
    }

Now, the problem is, when the form loads this screen pops up

http://i.stack.imgur.com/FouXC.png - http://i.stack.imgur.com/FouXC.png

So, my question is Why the hel* is it coming up? And, when this comes up, I don't enter anything! That's right! I just click finish and it loads the report perfectly! So, if it doesn't needs anything, why the hel* is it asking me for a login?

Also, is this a wrong way to do it, is that's why this window comes up? Is there another way? Anyways, the most important question is how can I get rid of that login window? Its of no use because I don't enter anything? So how?



Print Page | Close Window