locked
Two databases one report RRS feed

  • Question

  • User291339206 posted

    Hi,

    I need help. I have two exactly same databases i.e. 'Database1' and 'Database2' both with one table 'Table'. Now I need to create one report displaying some informations (not all) from 'Table'.  I would like to know how to programmicaly change datasource for report from 'Database1' to 'Database2'. I made report using OLE DB connection ('Database1' as initial database). Then I`ve tried something like this:

                ReportDocument crystalReport = new ReportDocument();
                crystalReport.Load(Server.MapPath("Test.rpt"));
                crystalReport.SetDatabaseLogon("sa", "sa", @"SERVER", "Database1");
                CrystalReportViewer.ReportSource = crystalReport;

    and thats working. Now if I change 'Database1' in SetDatabaseLogon to 'Database2' message 'The report you requested requires further information.' shows and I`m asked to enter loggon informations but can`t change database name which is still 'Database1'.

    I would be thankful for any advice or link.


    Majk from Slovakia

    Wednesday, September 9, 2009 4:40 AM

All replies

  • User-422529730 posted

    You can create datatable with  the data from both database and  then you can link your  report with datatable

    ex .

    DataTable dtInvoice = new DataTable();

    code to fill data table with desired data

    .

    ReportDocument RepDOC = new ReportDocument();
    RepDOC.Load(cryInvPath); // specify  path  in  app.config file
    RepDOC.Database.Tables[0].SetDataSource(dtInvoice); //set  dataset
    RepDOC.SetParameterValue("BillTo", strBillTo);

    Hope this will  help you

    Wednesday, September 9, 2009 7:56 AM
  • User291339206 posted

    Thanks for reply.

    But I don`t need fill report with data from both databases. I just need one report to be able to show informations no matter which database I choose. (every database has same table just different data).

    Another one: If I create new report using OLE DB I have to fill server, user ID, password and database in Connection Information. Now what if I need to connect this report to the same database but on another server? Since I entered server in Connection Information Window during report creating won`t this report fail to connect on another server?

                ReportDocument crystalReport = new ReportDocument();
                crystalReport.Load(Server.MapPath("Test.rpt"));
                crystalReport.SetDatabaseLogon("sa", "sa", @"SERVER", "database");
                CrystalReportViewer.ReportSource = crystalReport;

    if I change server name in this code from 'SERVER' to 'SERVER2' it just ask me to fill password but it still connects to server which was entered in Connection Information Window.


    Please help

    Wednesday, September 9, 2009 9:00 AM
  • User-1103262355 posted

    did you found the solutions? i am looking the same. Please share code if you have already...

    thank you

    Sunday, January 30, 2011 1:26 AM