alexg

alexg

  • NA
  • 1
  • 0

Crystal Report DB connection from code

Dec 6 2004 4:57 PM
Dear colleagues, I’m writing C# app working with access 200 db. It is supposed to use DSNless ODBC connection string to avoid setting ODBC connection in control panel on every client PC. I have to use Crystal Report as my reporting tool. My problem is to connect reports to db from the code. When the next code is executed, it brings me Database Login screen and says “LogOn failed” every time I click Ok. Code: ReportDocument ReportDoc = new ReportDocument(); ReportDoc.Load(“c:\report.rpt”); try { TableLogOnInfo logOnInfo = new TableLogOnInfo (); int i = 0; // Loop through every table in the report. for (i=0;i < ReportDoc.Database.Tables.Count;i++) { logOnInfo.ConnectionInfo.ServerName = ""; logOnInfo.ConnectionInfo.UserID = "admin"; logOnInfo.ConnectionInfo.Password = ""; logOnInfo.ConnectionInfo.DatabaseName = “c:\database.mdb”; ReportDoc.Database.Tables [i].ApplyLogOnInfo (logOnInfo); } return true; } catch (Exception ex) { return false; } crystalReportViewer1.ReportSource = ReportDoc; Thanks in advance