pratibhamohanty 0 Newbie Poster

Hello all,

I need immediate help on this. I need to pass the datasource name dynamically to a crystal report. In the design time , the report is connected to a particular datasource. What I am trying to do is trying to pass another datasource name dynamically in the load event of the form that has the crystalreport viewer control. But every time I try to load the report, it throws an error saying Login failed. I made sure the password, servername and database name is correct. I used the following code

'code starts here

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


Dim cryRpt As New ReportDocument
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table

cryRpt.Load("crystal report path"\crystalreport1.rpt")

With crConnectionInfo
.ServerName = "server name"
.DatabaseName = "database name"
.UserID = "username"
.Password = "password"
End With

CrTables = cryRpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next

CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()


End Sub

End Class

'code ends here.....


Thanks in advance