Link to home
Start Free TrialLog in
Avatar of carmodyk
carmodykFlag for United States of America

asked on

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.

ASKER CERTIFIED SOLUTION
Avatar of willbdman
willbdman
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of carmodyk

ASKER

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.