nater1111

 windows xp pro sp2

sql server 2k5

visual studio 2k5 .net 2.0

 

the problem:

i am using c#  and crystal reports 8.5  i am having issues with a report that uses 2 sql database tables.  i have 2 dsn's setup ( dsn1 and dsn2).  i am unsure how to dynamically determine which LogOnInfo to apply to each table.  for instance my current code is...

foreach (CrystalDecisions.CrystalReports.Engine.Table tablePrint in rd.Database.Tables)

{

TableLogOnInfo tloiPrint = tablePrint.LogOnInfo;

//assign logon info to object

tloiPrint.ConnectionInfo.ServerName = "dsn1";

tloiPrint.ConnectionInfo.IntegratedSecurity = true;

//apply logon info to table object

tablePrint.ApplyLogOnInfo(tloiPrint);

}

but this only applies the dsn1 logon info to both tables.  what i need is to find a property of the Table object that gives me the database name so i can dynamically apply logon info to the appropriate tables.

any ideas

thank you!




Re: Crystal Reports for Visual Studio Dynamically Get Database and Server from (Crystal) ReportDocument.Table object

nater1111

i answered my own question....

//logon to each table using table object connectioninfo

foreach (CrystalDecisions.CrystalReports.Engine.Table tablePrint in rd.Database.Tables)

{

TableLogOnInfo tbloiLogon = tablePrint.LogOnInfo;

tbloiLogon.ConnectionInfo.DatabaseName = tablePrint.LogOnInfo.ConnectionInfo.DatabaseName;

tbloiLogon.ConnectionInfo.ServerName = tablePrint.LogOnInfo.ConnectionInfo.ServerName;

tbloiLogon.ConnectionInfo.UserID = "userid1";

tbloiLogon.ConnectionInfo.Password = "username1";

tablePrint.ApplyLogOnInfo(tbloiLogon);

}