[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Non-Embedded Crystal Report to Change Database Connection at RunTime

Hello Experts,

I am desperately trying to get a Crystal Report, that resides outside of the program, to change databases.  I've been able to develop the report based on tables from my SQL database on my local computer, but now when I apply it to the client's computer, it won't work as it keeps asking for the database connection, etc.  Here is my Code that I'm working:

 Dim cryNoPro As New ReportDocument
 Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim intCount as integer

cryNoPro.Load(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) & "\Reports\MyReport.rpt")

ConInfo.ConnectionInfo.ServerName = "clientComputer"
 ConInfo.ConnectionInfo.UserID = "clientUSERID"
 ConInfo.ConnectionInfo.Password = "clientPassword"
 ConInfo.ConnectionInfo.DatabaseName = "clientDBName"

 For intCount = 0 To cryNoPro.Database.Tables.Count - 1

crystalReportViewer1.ReportSource = cryNoPro

What happpens is that the report is loaded, but then it asks for the database connection.  And even if you put in the database connection, the report then errors out with the error showing my database connection settings, not the ones I passed to the report!  What the heck!!!

Any help would be greatly appreciated.

1 Solution
Here is what i've used to load up external reports:-

'####  Sets up the viewer to display the correct report  ####
    Public Sub setViewer(ByVal strReportIn As String, ByVal dteFrmIn As Date, ByVal dteToIn As Date, _
                            Optional ByVal strUserIn As String = "NONE")

        'Stores tables from report
        Dim tblsBBL As Tables

        'Stores table from report
        Dim tblBBL As Table

        Try 'try to load report file

            'Load report file

        Catch ex As Exception

            'Display error message
            MessageBox.Show("Error locating report file, contact administrator.", "Report Error" _
                                , MessageBoxButtons.OK, MessageBoxIcon.Error)


        End Try

        'Set the tables to those in the report
        tblsBBL = rptBBL.Database.Tables

        'For each table in the report, set to new location
        For Each tblBBL In tblsBBL

            tblBBL.Location = "Specify your database location here"


    End Sub
carmodykAuthor Commented:
Actually, I've already solved the problem.  I went to http://support.businessobjects.com/library/kbase/articles/c2010371.asp and followed the example code to a tee.  Apparently I needed to include the database name in the table location.

crTable.Location = "MyDatabaseName" & 
".") + 1)

But I'll give you some points for at least trying.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now