p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Crystal Reports for VS.NET (http://p2p.wrox.com/forumdisplay.php?f=45)
-   -   Passing Database Logon Info (http://p2p.wrox.com/showthread.php?t=24185)

happyslug January 20th, 2005 05:43 AM

Passing Database Logon Info
On p123 of 2nd edition, it describes how to pass logon info to a report.

1. Firstly, I have converted the code to c# (please see below - is it correct)

2. So I created a report using OLD DB(ADO), which is my prefered method of connection, and used the c# code. Nothing changed. The report was run, connected to database1 and used only 1 table being vat, just as if I did not have the code. What I wanted to do was run the same report against database2 which also has a vat table.

But the report simply printed out data from database1.

3. I then created a report using ODBC(RDO). This time, I get a database login screen. It shows it is against table vat and then asks for server name (which is set to (local)), database which is blank and nothing appears in the dropdown, login id of sa and blank password. Even if I type in here either database1 or 2, I get login failed.

If I do not include the code the report just works off database1.

4. here is c# code

CrystalReport3 myReport = new CrystalReport3();

CrystalDecisions.Shared.TableLogOnInfos myTableLogonInfos = new CrystalDecisions.Shared.TableLogOnInfos();
CrystalDecisions.Shared.TableLogOnInfo myTableLogonInfo = new CrystalDecisions.Shared.TableLogOnInfo();
CrystalDecisions.Shared.ConnectionInfo myConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

myConnectionInfo.ServerName = "(local)";
myConnectionInfo.DatabaseName = "database2";
myConnectionInfo.UserID = "sa";
myConnectionInfo.Password = "";

myTableLogonInfo.ConnectionInfo = myConnectionInfo;
myTableLogonInfo.TableName = "vat";

crystalReportViewer1.LogOnInfo = myTableLogonInfos;

crystalReportViewer1.ReportSource = myReport;

5. Also, what would the foreach code look like?

vasanti February 14th, 2005 08:48 AM

Try This :

Database crDatabase;
Tables crTables;
TableLogOnInfo crTableLogOnInfo;
ConnectionInfo crConnectionInfo;

crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName= ServerName;
crConnectionInfo.DatabaseName = DatabaseName
crConnectionInfo.UserID = UserName;
crConnectionInfo.Password = Password;

crDatabase = CRObject.Database;
crTables = crDatabase.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
    crTableLogOnInfo = crTable.LogOnInfo;
    crTableLogOnInfo.ConnectionInfo = crConnectionInfo;


All times are GMT -4. The time now is 11:04 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.