RE: can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?
From: Mark Lauser .com> (Mark_at_CrimsonSoftware
Date: 02/27/04
- Next message: Herfried K. Wagner [MVP]: "Re: distributing windows services"
- Previous message: Francis Ingels [MSFT]: "Re: Treeview Help"
- In reply to: Bernie Yaeger: "can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Next in thread: Bernie Yaeger: "Re: can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Reply: Bernie Yaeger: "Re: can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Reply: Bernie Yaeger: "Re: can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 26 Feb 2004 17:21:05 -0800
Bernie,
I have gone through this, and the following code circumvents all of the known bugs that I worked through to resolve the problem. Apparently there are more obvious ways to handle this that simply don't work (or didn't when I wrote the code).
I store connection information in a 'Registration' dll file that is located on each client. That way I can have an identical application running on many different clients, and each uses it's own set of connection info to get to the appropriate server and database. You could also use application settings that the users can change themselves.
With this in place, I can create or revise reports on my dev machine and simply copy the report file to any and all clients with no changes at all, which was the main goal. The clients do not need Crystal Reports, and you certainly don't have to build the reports for each client.
One note: this particular method will not work if you use Windows Integrated Security to connect the report to the database on your dev machine. So, if you used Integrated Security, and you want to use this code, open each report, change the database connection to use a UserName & Password, and re-save it. I informed Crystal that it would be really nice if this could be changed at run-time, but I am not aware if they have accomplished this yet.
Declarations...
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
....
'Pass connection info
Dim crTableLogonInfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crTable As Table
Dim subRepDoc As New ReportDocument
Dim crSection As Section
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
With crConnectionInfo
.DatabaseName = <<Insert DatabaseName>>
.ServerName = <<Insert ServerName or IP Address and Port>>
.UserID = <<Insert UserID>>
.Password = <<Insert Password>>
End With
crTableLogonInfo.ConnectionInfo = crConnectionInfo
'CurrentReport is the ReportDocument loaded from a file earlier in this subroutine
For Each crTable In CurrentReport.Database.Tables
crTable.ApplyLogOnInfo(crTableLogonInfo)
crTable.Location = crTable.Name
Next
'If you have any sub-reports, they need the connection info too...
For Each crSection In CurrentReport.ReportDefinition.Sections
For Each crReportObject In crSection.ReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
crSubreportObject = CType(crReportObject, SubreportObject)
subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
For Each crTable In subRepDoc.Database.Tables
crTable.ApplyLogOnInfo(crTableLogonInfo)
crTable.Location = crTable.Name
Next
End If
Next
Next
'ReportViewer is the Crystal Reports Forms viewer on my form
ReportViewer.ReportSource = CurrentReport
I hope this prevents the same headaches that I had to go through to get here...
Best Regards,
Mark Lauser - Crimson Software
- Next message: Herfried K. Wagner [MVP]: "Re: distributing windows services"
- Previous message: Francis Ingels [MSFT]: "Re: Treeview Help"
- In reply to: Bernie Yaeger: "can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Next in thread: Bernie Yaeger: "Re: can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Reply: Bernie Yaeger: "Re: can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Reply: Bernie Yaeger: "Re: can't get an answer to a crystal rpt question re database connection - Cor, Herfried, Armin, Ken Tucker?"
- Messages sorted by: [ date ] [ thread ]