0
votes

After searching internet and answers here I am still not in a position of getting my problem resolved, I'm trying to use crystal report in c# Windows Form Application. I used Field Explorer in .rpt file to populate database fields in crystal report. then using the following code I called .rpt file in form (Comments below were added later by exploring the internet.)

        //ReportDocument report = new ReportDocument();
        //TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        //TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();

        // Tables CrTables ;
        // report.Load("rpt_DailyLog.rpt");
        Reports.rpt_GRN report = new Reports.rpt_GRN();
        // ConnectionInfo crConnectionInfo = new ConnectionInfo();
        //report.Load("rpt_GRN.rpt");
        //crConnectionInfo.ServerName = ".\sql2008";
        //crConnectionInfo.DatabaseName = "ARM";
        //crConnectionInfo.UserID = "sa";
        //crConnectionInfo.Password = "test123";

        stringcondition = "{GRN.Date}='" + date + "'";
        report.RecordSelectionFormula = stringcondition;

        //CrTables = report.Database.Tables ;
        //foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        //{
        //    crtableLogoninfo = CrTable.LogOnInfo;
        //    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
        //    CrTable.ApplyLogOnInfo(crtableLogoninfo);
        //}
        //crystalReportViewer1.LogOnInfo.Item(0).ConnectionInfo.UserID = "sa"
        //crystalReportViewer1.LogOnInfo.Item(0).ConnectionInfo.Password = "sapassword"
        crystalReportViewer1.ReportSource = report;
        crystalReportViewer1.Refresh();

Issue is: I am getting prompt when crystal report is loaded to give password while other fields i.e server name, database name and username is automatically populated, while it asks only for password. I don't want this prompt. Kindly help

2

2 Answers

0
votes

Please check once again whether you have given the user credentials both while designing the crystal report and in the code.The logon credentials which you give in the wizards should also match the logon credentials in your code. Check Once.

0
votes

I don't believe the password can be saved in the .rpt file which is why you are being prompted when running.

You have the code (commented) that you need to set the connection info:

    ConnectionInfo crConnectionInfo = new ConnectionInfo();
    crConnectionInfo.ServerName = ".\sql2008";
    crConnectionInfo.DatabaseName = "ARM";
    crConnectionInfo.UserID = "sa";
    crConnectionInfo.Password = "test123";
    CrTables = report.Database.Tables ;
    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
    {
        crtableLogoninfo = CrTable.LogOnInfo;
        crtableLogoninfo.ConnectionInfo = crConnectionInfo;
        CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }

It looks like you are using your own function Reports.rpt_GRN() where you'll need to implement the above.