Non-Embedded Crystal Report to Change Database Connection at RunTime

Posted on 2006-06-07
Last Modified: 2010-05-18
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.

Question by:carmodyk
    LVL 6

    Accepted 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
    LVL 6

    Author Comment

    Actually, I've already solved the problem.  I went to 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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now