【问题标题】:Crystal Report can't connect to database水晶报表无法连接数据库
【发布时间】:2012-12-06 22:11:49
【问题描述】:

我正在使用 Visual Studio 在 VB.net 中创建一个程序,并且某些表单使用 Crystal Reports 来显示 PDF 报告,但我遇到了数据库连接问题。 VB.net 代码可以毫无问题地访问数据库,但是当表单显示报告时,它会要求我输入用户名和密码,如果我编写它们,则无法连接。应用程序和报表共享同一个数据库,我使用相同的数据进行连接,但 Crystal Reports 失败。你能帮帮我吗?

【问题讨论】:

  • 您能否显示您用于创建和打开 Crystal Report 的代码?
  • 我没有使用任何代码来创建报告,我已经使用 Visual Studio Designer 完成了所有工作。首先,我创建了报表,然后创建了一个带有 CrystalReportViewer 的表单,链接到创建的报表。还有一个奇怪的事情,如果我在visual studio中尝试报告它可以工作,只有在我运行应用程序时才会出现问题
  • 嗯,我对设计师不是很有经验。
  • 您能否描述一下您执行的步骤。例如:1。我在我的表单中添加了一个 reportViewer。 2.我添加一个rpt文件到reportViewer等
  • 1.创建报表,2. 使用报表查看器创建表单,3. 将报表查看器链接到创建的报表,4. 运行应用程序

标签: vb.net visual-studio-2010 crystal-reports database-connection


【解决方案1】:

这是我有的一个可以工作的 sn-p(在 C# 中,但应该让您了解我是如何做到的):

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

【讨论】:

    【解决方案2】:

    虽然你说你在使用设计师,但我会发布一些对我有用的代码,也许它会对你有所帮助:

           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
    

    【讨论】:

    • 谢谢,但我不能使用数据表,我需要它直接连接到数据库
    【解决方案3】:

    在“SetDataSource”中设置时检查数据中是否存在所有字段

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 2010-10-28
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      相关资源
      最近更新 更多