Crystal Report database connection

dingo1495

Member
Joined
Jun 20, 2005
Messages
5
Programming Experience
3-5
Hi guy's,

Think this is a easyone for all the code masters....

I am trying to run my Crystal Reports in a VB .NET application. I have worked out how to supply the report with the parameters, but I havent been able to work out how to 'give' the report the database connecting. So at the moment Crystal Reports asks for the database login details at run time.

How can I supply either the crystal report or the crystal report viewer with the database connection string?

Thank you for your help
 
Hi,
Crystal reports Viewer cannot be connected with database ... it's primer assignment is displaying of .rpt files.

About the .rpt; there is not a way to establish connection for the reports with string connection but rather you have to do that through field explorer. How do you think to have the visual view of tables, columns, views and stuff in runtime if you make string connection. But, maybe you want to use dataset object for the purpose? Just add elements to the DataSet which you want on the report. Also you can pass everything from forms through text object.

Cheers ;)
 
hmmm but as for as i think you can connect crystal report using following code. (awww it is alos tested one too .... )

first include two namespaces
using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

and then write the following code to load the report.
ReportDocument report = new ReportDocument();

ConnectionInfo conInfo =
new ConnectionInfo();

report.Load ("your path to file");



conInfo.ServerName = "DSN Or server name";

conInfo.DatabaseName = "database name";

conInfo.Password = "password";

conInfo.UserID = "userid";



foreach(Table table in report.Database.Tables)

{

TableLogOnInfo tableInfo =
new TableLogOnInfo() ;

tableInfo.ConnectionInfo = conInfo;

table.ApplyLogOnInfo(tableInfo);

}
this.crystalReportViewer1.ReportSource = report ;

this.crystalReportViewer1.Show ();

 
Thanks to everyone that made a effort... but I found how to do it in VB.NET the c# stuff helped get me on the right track.

This works for me.
...
...
..
rptLogin(crReport.Database.Tables)
.....
..
.
Sub rptLogin(ByVal crTables As Tables)

Dim crConnectionInfo As New ConnectionInfo()
Dim CrTable As Table
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()

With crConnectionInfo
.ServerName = "DSN or server name"
.DatabaseName = "nnnnnn"
.UserID = "nnnnnn"
.Password = "nnnn"
End With

For Each CrTable In crTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next

End Sub
 
Back
Top