0
votes

I'm creating a program in VB.net with Visual Studio and some forms use Crystal Reports to show PDF reports, but i'm having problems with database connection. VB.net code can access the databse without problems, but when a form shows a report it asks me for username and password and if i write them it fails to connect. The application and the reports share the same database and i use the same data to connect, but Crystal Reports fails. Can you help me?

3
Can you show as the code that you are using to create and open the Crystal Report?Nianios
I haven't use any code to create the report, i've done everything using visual studio designer. First i've created the report, then i've created a form with a CrystalReportViewer linked to the created report. There is also another strange thing, if i try the report in visual studio it works, the problem appears only when i run the applicationmck89
mmm, I am not so experienced with the designers.Nianios
Could you please describe the steps that you did. For example:1. I add a reportViewer in my Form. 2. I add an rpt file to reportViewer , etcNianios
1. created the report, 2. created the form with the reportviewer, 3. linked the reportviewer to the created report, 4. run the applicationmck89

3 Answers

1
votes

Here's a snippet that I have that works (in C#, but should give you an idea of how I did it):

    CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
    CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();

    CrystalReportViewer1.ReportSource = CrystalReportSource1;
    CrystalReportViewer1.EnableParameterPrompt = false;
    CrystalReportSource1.Report.FileName = "Report3.rpt";
    CrystalReportSource1.EnableCaching = false;

    CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
    CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);



    TableLogOnInfo logOnInfo = new TableLogOnInfo();

    logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"];
    logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"];
    logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"];
    logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"];

    TableLogOnInfos infos = new TableLogOnInfos();
    infos.Add(logOnInfo);
    CrystalReportViewer1.LogOnInfo = infos;

    maindiv.Controls.Add(CrystalReportSource1);
    maindiv.Controls.Add(CrystalReportViewer1);


    CrystalReportViewer1.DataBind();
0
votes

Although you said that you are using the designers, I 'll post some code that is working for me, maybe it will help you:

       Dim cryRpt As New ReportDocument
       Dim strReportPath As String = 'The Path of the rpt file
       cryRpt.Load(strReportPath)
       cryRpt.SetDataSource(Me.crData) 'crData is a datatable with data for the report

       crvReport.ReportSource = cryRpt 'crvReport is the CrystalReportViewer in my form
0
votes

Check if all fields exist in the data when you set in "SetDataSource"