Crystal Reports and Path to DB 
Author Message
 Crystal Reports and Path to DB

Can anyone give me guidance as to how (in code) you can change the database
a Crystal Report is pointing to?  I found the database property .. but it
tells me that it is read only.

Any direction would be greatly appreciated!

Thank you!

Rob



Sun, 24 Jul 2005 08:07:22 GMT  
 Crystal Reports and Path to DB
Hello


Quote:
> Can anyone give me guidance as to how (in code) you can change the
database
> a crystal report is pointing to?  I found the database property .. but it
> tells me that it is read only.

Here is a sample I found and adapted. It works for me using an Access
database.

    Private Sub Report_DefineLogonInfo(ByVal oReport As Object, ByVal
sStoredProcedureName As String, ByVal sDSTableName As String)

        ' oReport is the report you are editing
        ' sStoredProcedureName is the name of the stored procedure (or
query) you are using
        ' sDSTableName is the name of the table you are updating in your
dataset.

        Dim oLogonInfo As CrystalDecisions.Shared.TableLogOnInfo

        myCrystalReportViewer.LogOnInfo = New
CrystalDecisions.Shared.TableLogOnInfos()
        oLogonInfo = New CrystalDecisions.Shared.TableLogOnInfo()
        oLogonInfo.TableName = sStoredProcedureName

        With oLogonInfo.ConnectionInfo
            .ServerName = DBPath                ' REPLACE WITH THE PATH TO
YOUR DATABASE
            .DatabaseName = ""
            .UserID = UserId                            ' REPLACE WITH YOUR
USERID
            .Password = Password                    ' REPLACE WITH YOUR
PASSWORD
        End With

        myCristalReportViewer.LogOnInfo.Add(oLogonInfo)
        CType(oReport,
CrystalDecisions.CrystalReports.Engine.ReportDocument).SetDataSource(myDatas
et.Tables(sDSTableName))

        myCrystalReportViewer.RefreshReport()

    End Sub

Here is a sample I found and adapted. It works for me using an Access
database.
If you have several tables in your dataset, you will have to change the
location for all tables of your dataset.
You can have more information at the following URL:
http://www.crystalreportsbook.com/Chapter14.asp (you may be asked for
registration before accessing the page).

Depending the database you are accessing, you will have to set correctly the
ServerName and/or DatabaseName properties, like indicated in the following
table.

      Database
     ServerName Property
     DatabaseName Property

      Access
     The fully qualified file path
     Leave it blank

      SQL Server[9]
     The server name
     The database name

      ODBC Driver
     The DSN name
     Leave it blank

Hope it helps you.

    MichaelP



Sun, 24 Jul 2005 17:52:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Crystal Report: DB Path manipulation in VB code

2. Crystal Reports - relative path in report file name

3. Can you define report path for crystal reports?

4. Printing Crystal Reports without Crystal Control ActiveX or Crystal Reports API call

5. changing .mdb path in crystal report using vb 4.0

6. Crystal Report Path

7. Image Path's & Crystal Reports

8. Crystal reports path

9. Crystal report path

10. Set the Data Link File path in crystal report by Visual Basic coding

11. .mdb file path in crystal report

12. changing .mdb path in crystal report using vb 4.0

 

 
Powered by phpBB® Forum Software