Non-Embedded Crystal Report to Change Database Connection at RunTime
Posted on 2006-06-07
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.