簡體   English   中英

Crystal Report無法連接到數據庫

[英]Crystal Report can't connect to database

我正在使用Visual Studio在VB.net中創建一個程序,某些表單使用Crystal Reports顯示PDF報告,但是我在數據庫連接方面遇到問題。 VB.net代碼可以毫無問題地訪問數據庫,但是當表單顯示報告時,它會詢問我用戶名和密碼,如果我寫了它們,它將無法連接。 該應用程序和報表共享相同的數據庫,並且我使用相同的數據進行連接,但是Crystal Reports失敗。 你能幫助我嗎?

這是我可以使用的代碼段(在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();

盡管您說您正在使用設計師,但我將發布一些對我有用的代碼,也許它將對您有所幫助:

       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

在“ SetDataSource”中設置時,檢查數據中是否存在所有字段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM