Change database name in crystal report ?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

Please help, i had completed over 30-50 reports, now. our client insist to
change the database name.
anyshorcut that I can change the database name in the report without
re-write all of them ??
Thanks in advance
 
Hi, maybe this can help:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource

Private crParameterFields As New ParameterFields
Private crReportDocument As New ReportDocument

Public Sub InitialiseReport(ByVal psReportName As String, ByVal psTitle As
String)
Dim tblCurrent As Table
Dim crSubreportObject As SubreportObject
Dim subRepDoc As New ReportDocument
Dim crDatabase As
CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As Tables
Dim crTable As Table
Dim crSection As Section
Dim crSections As Sections
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crLogOnInfo As TableLogOnInfo
Dim crpConnectionInfo As New
CrystalDecisions.Shared.ConnectionInfo
Dim crpTableLogOnInfo As New
CrystalDecisions.Shared.TableLogOnInfo


crReportDocument.Load(psReportName)
CrystalReportViewer1.ReportSource = crReportDocument

'
' change server for main report
'
With crpConnectionInfo
.ServerName = "yourservername"
.DatabaseName = "yourdatabase"
End With

'if integrated security isn't true

crpConnectionInfo.UserID = "userid"
crpConnectionInfo.Password = "password"


For Each tblCurrent In crReportDocument.Database.Tables
crpTableLogOnInfo = tblCurrent.LogOnInfo
crpTableLogOnInfo.ConnectionInfo = crpConnectionInfo
tblCurrent.ApplyLogOnInfo(crpTableLogOnInfo)
Next

'Set the sections collection with report sections
crSections = crReportDocument.ReportDefinition.Sections
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind =
ReportObjectKind.SubreportObject Then

'If you find a subreport, typecast the reportobject
to a subreport object
crSubreportObject = CType(crReportObject,
SubreportObject)

'Open the subreport
subRepDoc =
crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)

crDatabase = subRepDoc.Database
crTables = crDatabase.Tables

'Loop through each table and set the connection info
'Pass the connection info to the logoninfo object
then apply the
'logoninfo to the subreport

For Each crTable In crTables
With crpConnectionInfo
.ServerName =
FalProjectFuncties.OphalenConfigWaarde("CrystalReport", "Servernaam")
.DatabaseName =
FalProjectFuncties.OphalenConfigWaarde("CrystalReport", "Database")
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crpConnectionInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
Next
End If
Next
Next


End Sub

Hth greetz Peter
 
Thank Peter, However, as i modify the report, it still link back to the old
database.
 
Hi in crystal reports you can go to Database and then select set datasource
location

hth Greetz Peter
 
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

I just love your signature Peter... :-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top