1

我已经为 Visual Studio.Net 2010 (CRforVS_13_0_4) 安装了 Crystal Reports 并创建了许多报告,只要我的 PC 与我创建报告的位置相同,这些报告就可以使用以下代码正常工作。(报告是在后端使用存储过程创建的)....但是当我移动到另一台 PC 时,所有报告都给出错误。

Failed to retrieve data from database" 
Details: [Database Vendor Code 2812] 
Error in File ItemTypesReport (ItemTypes Report is the Crystal Report)

以下是我的代码。

Public Sub Preview_ReportWithParameters(ByVal CrystalReportName As String)
        Try
            If SqlConn.State = 1 Then SqlConn.Close()
            Dim frmReport As New ReportDisplay
            Dim crDocument As New ReportDocument


            Dim reportPath As String = My.Application.Info.DirectoryPath + "\" + CrystalReportName + ".rpt"
            crDocument.Load(reportPath)
            crDocument.SetParameterValue("@UserID", Convert.ToInt64(mUserID))
            crDocument.SetParameterValue("@ActionCode", "1")
            crDocument.SetParameterValue("@SearchText", "")


            Dim crConnectionInfo As ConnectionInfo = New ConnectionInfo()
            crConnectionInfo.ServerName = mSQLServername
            crConnectionInfo.DatabaseName = mSQLDatabaseName
            crConnectionInfo.UserID = mSQLUser
            crConnectionInfo.Password = mSQLPassword
            Dim crTables As Tables = crDocument.Database.Tables
            For Each crTable As CrystalDecisions.CrystalReports.Engine.Table In crTables
                Dim crTableLogonInfo As TableLogOnInfo = crTable.LogOnInfo
                crTableLogonInfo.ConnectionInfo = crConnectionInfo
                crTable.ApplyLogOnInfo(crTableLogonInfo)
            Next
            frmReport.crViewer.ReportSource = Nothing
            frmReport.crViewer.DataBindings.Clear()
            frmReport.crViewer.ReportSource = crDocument
            frmReport.Show()
            frmReport.Refresh()
            SqlConn.Close()
            'crDocument.Dispose()
        Catch ex As Exception
            'If Err.Number = 5 Or Err.Number = 91 Then
            '    MsgBox("Sorry, no record is selected to preview, you must select a record.", MsgBoxStyle.Information, "No record selected")
            'Else
            MsgBox("Error No: " & Err.Number & vbNewLine & ex.ToString, MsgBoxStyle.Information, "No record selected")
            'End If
        End Try
    End Sub

调用上述程序

Preview_ReportWithParameters("ItemTypesReport")
4

0 回答 0