Skip to Content
0
Former Member
Jun 29, 2009 at 07:57 PM

Changing Dataconnection

34 Views

All of our current reports are using ODBC and crystal report 9. We are converting them to 2008 crystal reports and using ASP.net 3.5. I found that the crystalreportview was very slow. I tried to change data connection method at run-time by using:

Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()

myConnectionInfo.ServerName = "ServerName"

myConnectionInfo.DatabaseName = "DatabaseName"

myConnectionInfo.UserID = "UserId"

myConnectionInfo.Password = "Password"

SetDBLogonForReport(myConnectionInfo, rdoc)

SetDBLogonForSubreports(myConnectionInfo, rdoc)

Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)

Dim myTables As Tables = myReportDocument.Database.Tables

Dim myTable As CrystalDecisions.CrystalReports.Engine.Table

For Each myTable In myTables

Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo

myTableLogonInfo.ConnectionInfo = myConnectionInfo

myTable.ApplyLogOnInfo(myTableLogonInfo)

Next

End Sub

Private Sub SetDBLogonForSubreports(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)

Dim mySections As Sections = myReportDocument.ReportDefinition.Sections

Dim mySection As Section

For Each mySection In mySections

Dim myReportObjects As ReportObjects = mySection.ReportObjects

Dim myReportObject As ReportObject

For Each myReportObject In myReportObjects

If myReportObject.Kind = ReportObjectKind.SubreportObject Then

Dim mySubreportObject As SubreportObject = CType(myReportObject, SubreportObject)

Dim subReportDocument As ReportDocument = mySubreportObject.OpenSubreport(mySubreportObject.SubreportName)

SetDBLogonForReport(myConnectionInfo, subReportDocument)

End If

Next

Next

End Sub

To replace rdoc.SetDatabaseLogon("UserId", "Password")

However, I got login-error: Failed to open the connection at the step of CrystalReportViewer1.ReportSource = rdoc. Can you tell me why?