Home All Groups Group Topic Archive Search About

Crystal Report Database Change

Author
14 Apr 2005 10:49 AM
Jasper Jones
Hi, I've designed several Crystal Reports using the built in wizard.
They point to my database as HQ which is called "Thom". There is a
database called Sales on Thom which all the reports point to and get
their results from.

I'm ready to compile my program to give to the users at a different
site.  They have a database server there called "Sidney" which had a
copy of the same "Sales" database on there.  Is there a way I can
change the database of my report when I load it each time, it looks
like I'd have to go through each individual report and change the
database settings which would be very time consuming as I will be using
quite a few database servers with this program.  I'd like to just
specify a database or dataset in the code.

This is how I call the report:

        Dim Cr As New crRefunds

        CrystalReportViewer1.ReportSource = Cr

it would be ideal if I could put a line in above, something like
cr.database = "Sidney".  Is anything like this possible?  If not what
is the best way to switch the database?

Any help or pointers will be greatly appreciated as I'm really stuck
with this one.

Author
14 Apr 2005 11:31 AM
Peter Proost
Maybe this code can help you, I use it to run my reports on different db's
ofcourse the tablenames have to be the same.

hth Greetz Peter

add reference to CrystalDecisions.CrystalReports.Engine.dll

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

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


        Dim crReportDocument As New ReportDocument
        crReportDocument.Load(psReportName)
        CrystalReportViewer1.ReportSource = crReportDocument
        CrystalReportViewer1.Zoom(2)
        '
        ' Aanpassen server voor hoofdrapport
        '
        With crpConnectionInfo
            .ServerName = "Yourserver"
            .DatabaseName = "YourDataBase"
        End With

        'set this if you don't work with integrated security
        'crpConnectionInfo.UserID = "user"
        '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 = "YourServer"
                            .DatabaseName = "YourDataBase"
                        End With
                        crLogOnInfo = crTable.LogOnInfo
                        crLogOnInfo.ConnectionInfo = crpConnectionInfo
                        crTable.ApplyLogOnInfo(crLogOnInfo)
                    Next
                End If
            Next
        Next


Show quoteHide quote
"Jasper Jones" <jasper***@gmail.com> schreef in bericht
news:1113475765.426286.222370@z14g2000cwz.googlegroups.com...
> Hi, I've designed several Crystal Reports using the built in wizard.
> They point to my database as HQ which is called "Thom". There is a
> database called Sales on Thom which all the reports point to and get
> their results from.
>
> I'm ready to compile my program to give to the users at a different
> site.  They have a database server there called "Sidney" which had a
> copy of the same "Sales" database on there.  Is there a way I can
> change the database of my report when I load it each time, it looks
> like I'd have to go through each individual report and change the
> database settings which would be very time consuming as I will be using
> quite a few database servers with this program.  I'd like to just
> specify a database or dataset in the code.
>
> This is how I call the report:
>
>         Dim Cr As New crRefunds
>
>         CrystalReportViewer1.ReportSource = Cr
>
> it would be ideal if I could put a line in above, something like
> cr.database = "Sidney".  Is anything like this possible?  If not what
> is the best way to switch the database?
>
> Any help or pointers will be greatly appreciated as I'm really stuck
> with this one.
>
Author
14 Apr 2005 12:11 PM
Jasper Jones
This looks good, Peter.  I will try this out now.  Many thanks.