Crystal Reports for Visual Studio.Net 2010 (CRforVS_13_0_4) をインストールし、多くのレポートを作成しました。レポートを作成した 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")