Hi Brian,
Actually, you can do that also.
Below is code I use to ensure that the tables and the database that a report
is connected to is the one I now want it to be connected to. This is
throughout my apps because I code on a system that refers to a given server
and my clients have a different name for the real server, but it has
application to exactly what you want to do. There is extraneous stuff
particular to my needs, but you'll get the point.
Let me know if you have any questions about this - I call it just before
sending the reportviewer control into action:
Public Sub connectionchange()
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 As Integer
crreportdocument.Load(gl_browseprintvar,
OpenReportMethod.OpenReportByTempCopy)
' gl_browseprintvar is the full path and name of the .rpt file to print
With crconnectioninfo
..DatabaseName = "IMC"
..ServerName = globalservername
..UserID = globalusername
..Password = globalpwd
End With
crtablelogoninfo.ConnectionInfo = crconnectioninfo
crtables = crreportdocument.Database.Tables
For Each crtable In crtables
crconnectioninfo.DatabaseName = "IMC"
crtablelogoninfo.ConnectionInfo = crconnectioninfo
crtable.ApplyLogOnInfo(crtablelogoninfo)
crtable.Location = crtable.Name
Next
Dim subRepDoc As New ReportDocument
Dim crSection As Section
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
'If you have any sub-reports, they need the connection info too...
For Each crSection In crreportdocument.ReportDefinition.Sections
For Each crReportObject In crSection.ReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
crSubreportObject = CType(crReportObject, SubreportObject)
subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
For Each crtable In subRepDoc.Database.Tables
crtable.ApplyLogOnInfo(crtablelogoninfo)
crtable.Location = crtable.Name
Next
End If
Next
Next
CrystalReportViewer1.ReportSource = crreportdocument
End Sub
HTH,
Bernie Yaeger