Logon(crReportDocument, ServerName, DatabaseName, UserID, Password) crReportDocument.SetParameterValue("@MYID", id) 'SQL SP Main crReportDocument.SetParameterValue("@MYID", id, "SUB1") 'SQL SP SUB1 crReportDocument.SetParameterValue("@MYID", id, "SUB2") 'SQL SP SUB2 crReportDocument.SetParameterValue("@MYID", id, "SUB3") 'SQL SP SUB3 CrystalReportViewer1.ReportSource = crReportDocument CrystalReportViewer1.Visible = True Private Function ApplyLogon(ByVal cr As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal ci As CrystalDecisions.Shared.ConnectionInfo) As Boolean ' This function is called by the "Logon" function ' It loops through the report tables and applies ' the connection information to each table. ' Declare the TableLogOnInfo object and a table object for use later. Dim li As CrystalDecisions.Shared.TableLogOnInfo Dim tbl As CrystalDecisions.CrystalReports.Engine.Table ' For each table apply connection info. For Each tbl In cr.Database.Tables li = tbl.LogOnInfo li.ConnectionInfo = ci tbl.ApplyLogOnInfo(li) ' Verify that the logon was successful. ' If TestConnectivity returns false, correct table locations. If (tbl.TestConnectivity()) Then ' If there is a "." in the location then remove the ' beginning of the fully qualified location. ' Example "dbo.northwind.customers" would become ' "customers". If (tbl.Location.IndexOf(".") > 0) Then tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1) Else ' If the location is not returning as a fully ' qualified location we still set it to tbl.location ' because Crystal Reports 9 installed on top of .NET ' can *store* fully qualified names but will only *return* ' the table name itself. tbl.Location = tbl.Location End If Else Return False End If Next Return True End Function ' The Logon method iterates through all tables. Private Function Logon(ByVal cr As CrystalDecisions.CrystalReports.Engine.ReportDocument, _ ByVal server As String, _ ByVal database As String, _ ByVal user_id As String, _ ByVal password As String) As Boolean ' Declare and populate a new connection info object. Dim ci As New CrystalDecisions.Shared.ConnectionInfo() With ci .ServerName = server .DatabaseName = database .UserID = user_id .Password = password End With ' If the ApplyLogon function fails then return a false for this function. ' We are applying logon information to the main report at this stage. If (Not ApplyLogon(cr, ci)) Then Return False End If ' Declare both a report object as well as a subreport object. Dim obj As CrystalDecisions.CrystalReports.Engine.ReportObject Dim subobj As CrystalDecisions.CrystalReports.Engine.SubreportObject ' Loop through all the report objects and locate subreports. ' If a subreport is found then apply logon information to ' the subreport. For Each obj In cr.ReportDefinition.ReportObjects If (obj.Kind = CrystalDecisions.[Shared].ReportObjectKind.SubreportObject) Then subobj = CType(obj, CrystalDecisions.CrystalReports.Engine.SubreportObject) If (Not ApplyLogon(cr.OpenSubreport(subobj.SubreportName), ci)) Then Return False End If End If Next ' Return True if the code runs to this stage. Return True End Function