Failed to Load Database Information in Crystal Rep
hi guys ,
we are using Crystal report for windows Application.when i get repot folling error Appears guide me.............
Failed to Load DataBase Information
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Data
Imports System.Windows.Forms
Public Class frmReport
Inherits System.Windows.Forms.Form
Dim Criteria As String
Dim ReportName As String
Private ReportDataSet As DataSet
Private strParamName() As String
Private strParamValue() As String
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
'ParameterValues and ParameterDiscreteValue are off the CrystalDecisions.Shared
'namespace
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
#Region " Windows Form Designer generated code "
Public Sub New(ByVal WhereClause As String, ByVal Rname As String, _
Optional ByVal Ds As DataSet = Nothing, Optional ByVal ParamName() As String = Nothing, _
Optional ByVal ParamValue() As String = Nothing)
MyBase.New()
Criteria = WhereClause
ReportName = Rname
ReportDataSet = Ds
strParamName = ParamName
strParamValue = ParamValue
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents rpt As CrystalDecisions.Windows.Forms.CrystalReportViewer
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.rpt = New CrystalDecisions.Windows.Forms.CrystalReportViewer
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'rpt
'
Me.rpt.ActiveViewIndex = -1
Me.rpt.DisplayBackgroundEdge = False
Me.rpt.DisplayGroupTree = False
Me.rpt.Dock = System.Windows.Forms.DockStyle.Fill
Me.rpt.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.rpt.Location = New System.Drawing.Point(0, 0)
Me.rpt.Name = "rpt"
Me.rpt.ReportSource = Nothing
Me.rpt.Size = New System.Drawing.Size(982, 531)
Me.rpt.TabIndex = 0
'
'Button1
'
Me.Button1.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button1.Location = New System.Drawing.Point(0, 0)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.TabStop = False
Me.Button1.Text = "Button1"
'
'frmReport
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.Button1
Me.ClientSize = New System.Drawing.Size(982, 531)
Me.Controls.Add(Me.rpt)
Me.Controls.Add(Me.Button1)
Me.Name = "frmReport"
Me.Text = "frmReport"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter
Dim crReportDocument As New ReportDocument
Dim NameCount As Integer
Dim ValueCount As Integer
winPlsWait = New frmStatus
winPlsWait.Show("Generating report....")
crReportDocument.Load(ReportName)
If Not strParamName Is Nothing Then
While NameCount <> strParamName.Length
crParameterDiscreteValue.Value = strParamValue.GetValue(NameCount).ToString
crParameterFieldDefinitions = crReportDocument.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item(strParamName.GetV alue(NameCount).ToString)
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crPa rameterValues)
NameCount = NameCount + 1
End While
End If
With crConnectionInfo
.ServerName = Configuration.ConfigurationSettings.AppSettings("s name")
.DatabaseName = Configuration.ConfigurationSettings.AppSettings("d name")
.UserID = "sa"
.Password = "manager"
End With
CrTables = crReportDocument.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
'''------------Subreport Database Logon Info
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocum ent
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportOb ject
Dim index As Integer
Dim intCounter, intCounter1 As Integer
For index = 0 To crReportDocument.ReportDefinition.Sections.Count - 1
For intCounter = 0 To crReportDocument.ReportDefinition.Sections(index). ReportObjects.Count - 1
With crReportDocument.ReportDefinition.Sections(index)
If .ReportObjects(intCounter).Kind = CrystalDecisions.Shared.ReportObjectKind.Subreport Object Then
mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportOb ject)
mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject. SubreportName)
Dim CrTables1 As Tables
Dim CrTable1 As Table
CrTables1 = mySubRepDoc.Database.Tables
For Each CrTable1 In CrTables1
crtableLogoninfo = CrTable1.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable1.ApplyLogOnInfo(crtableLogoninfo)
Next
End If
End With
Next
Next
'''------------------End
If ReportDataSet Is Nothing Then
rpt.ReportSource = crReportDocument
rpt.SelectionFormula = Criteria
Else
rpt.ReportSource = crReportDocument
crReportDocument.SetDataSource(ReportDataSet.Table s(0))
crReportDocument.SetDatabaseLogon("SA", "manager", Configuration.ConfigurationSettings. _
AppSettings("sname"), Configuration.ConfigurationSettings.AppSettings("d name"))
rpt.ReportSource = crReportDocument
rpt.SelectionFormula = ""
End If
winPlsWait = Nothing
rpt.RefreshReport()
rpt.Show()
End Sub
|