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

x
  • 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
       cryNoPro.Database.Tables(intCount).ApplyLogOnInfo(ConInfo)
 Next

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.

0
carmodyk
Asked:
carmodyk
1 Solution
 
willbdmanCommented:
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
            rptBBL.Load(strReportIn)

        Catch ex As Exception

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

            MsgBox(ex.Message)

           
        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"

        Next

    End Sub
0
 
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.

exp:
crTable.Location = "MyDatabaseName" & 
crTable.Location.Substring(crTable.Location.LastIndexOf(
".") + 1)
Next

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

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