Changeing CrystalReport.NET database in VB.NET code

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

Is it possible to change the database in which a crystalreports.net report
is linking to? we have a bunch of reports made that pull straight form the
database server, but work with differnet versions of it (all same table
structures) such as live and development. Can you tell a report to execute
off of a different database in vb.net?
 
Hi Brian,

In Crystal 9 and higher (perhaps lower as well, but I'm not sure), you can
go into database/ set database location and map replacement tables and
columns, simple by selecting the one to be replaced at the top, the table to
now use at the bottom and clicking 'update'; any data mapping problems will
be highlighted and will allow for manual alteration.

HTH,

Bernie Yaeger
 
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
 
Back
Top