I have two tables tbl_employee and tbl_department. I want to show a crystal report for employee information where department name should be there. When I am trying to show the report only for the employee table it is working fine but when I am joining these two tables with key in crystal report design, logon error exception is shown.
Can anyone please help me?
It looks like you are following the answer provided here https://qawithexperts.com/questions/138/how-to-show-only-a-single-record-with-crystal-report-in-aspn
Which looks ok to me & I don't think it is related to multiple table's data fetch but according to error mentioned by you in the image "Database Logon Failed" you need to provide database details while generating reports also, here is the example about how to generate reports with dynamic logon
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables ;
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");
crConnectionInfo.ServerName = "YOUR SERVER NAME";
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
CrTables = cryRpt.Database.Tables ;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-dynamic-login.htm
There is another complete tutorial on this https://www.aspdotnet-suresh.com/2012/01/crystal-reports-sample-in-aspnet.html
If that doesn't help you, check similar issue's
https://community.ivanti.com/thread/31347
Also, as per the answer here https://www.experts-exchange.com/questions/28520468/Database-logon-failed-when-exporting-Crystal-Report-to-PDF.html you need to have SQL native client installed.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly