Hello,
I wish to get the code to pass the log in information (i.e server name,pass word etc) as parameter at the time of calling report
Now its asking (user name ,password) before going to the report page each time .please help me.
shine_jose -6 Light Poster
Dani AI
Generated
Good start, — and useful example from . The common reason Crystal prompts for credentials at runtime is not that the technique is wrong, but that one or more data sources in the report weren’t updated at runtime (main tables, subreports, saved DSNs/locations or the report’s saved credentials). The viewer will still prompt if any table or subreport lacks the runtime logon info or if the web process identity cannot authenticate.
Apply the same logon update to every table in every subreport before assigning the ReportDocument to the viewer. A compact pattern:
foreach (ReportDocument sub in cryRpt.Subreports)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table t in sub.Database.Tables)
{
var logon = t.LogOnInfo;
logon.ConnectionInfo.ServerName = "SERVER";
logon.ConnectionInfo.DatabaseName = "DATABASE";
logon.ConnectionInfo.UserID = "USER";
logon.ConnectionInfo.Password = "PASSWORD";
t.ApplyLogOnInfo(logon);
}
}
cryRpt.SetDatabaseLogon("USER", "PASSWORD"); // helpful but not always enough alone
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.RefreshReport(); Troubleshooting checklist (quick):
- Verify subreports: they are the most common cause of repeated prompts.
- Check saved table locations/DSNs in the .rpt (Database → Set Datasource Location). If the report was designed against a DSN or another server, update Table.Location or the DSN.
- If the web app works differently than a console app, it’s an ASP.NET identity/impersonation issue — the app pool identity must have DB access if using Windows auth.
- Ensure the Crystal runtime on the server matches the design-time version. Version mismatch can cause odd prompts or failures.
- Always close/dispose the ReportDocument after use to avoid leaks: call Close() and Dispose() (and clear the viewer’s ReportSource).
Security note: avoid hard-coding DB passwords in code. Use secure configuration (encrypted config sections, Windows auth where possible) and restrict who can read stored credentials.
Ramesh S 129 Posting Pro
Try this.
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(); Reference: C# Crystal Reports Dynamic Logon parameters
Also refer this link.
bill_kearns commented: Thank you! +0
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.