mck89
mck89

Reputation: 19231

Crystal Report can't connect to database

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?

Upvotes: 0

Views: 2710

Answers (3)

Bernabé Tavarez
Bernabé Tavarez

Reputation: 351

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

Upvotes: 0

Andrew
Andrew

Reputation: 2839

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();

Upvotes: 1

Nianios
Nianios

Reputation: 1426

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

Upvotes: 0

Related Questions