I am trying to make a simple crystal report viewer application and I cannot get the viewer to set the login info. Basically want I want to do is on the click of a button it should open a report. Pretty simple I thought but apparently not. Here's my code
private void button1_Click(object sender, EventArgs e)
{
ConnectionInfo connInfo = new ConnectionInfo();
connInfo.ServerName = "SERVER NAME";
connInfo.DatabaseName = "DATABASE NAME";
connInfo.UserID = "USERNAME";
connInfo.Password = "PASSWORD";
crystalReportViewer1.ReportSource = GetReportSource(connInfo);
crystalReportViewer1.RefreshReport();
}
private ReportDocument GetReportSource(ConnectionInfo connInfo)
{
ReportDocument document = new ReportDocument();
document.Load("REPORTPATH");
document.SetParameterValue(0, "04/02/2014");
document.SetParameterValue(1, "04/03/2014");
TableLogOnInfos logonInfos = new TableLogOnInfos();
TableLogOnInfo logonInfo = new TableLogOnInfo();
Tables tables;
tables = document.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
logonInfo = table.LogOnInfo;
logonInfo.ConnectionInfo = connInfo;
table.ApplyLogOnInfo(logonInfo);
}
return document;
}
The worst part is that this code works FINE on one of my computers but not the one I WANT it to work on. Again, this code totally compiles and works on one of my computers but not the other and I cannot figure out for the life of me why. God I hope someone can help.
When I run the program and click the button, it prompts me for the username and password, however when I enter it, it says "Login failed" another problem is that the "Database" field isn't populated on the login form even though it should be.
OK I solved this. Not entirely sure why this worked but I'll post what I did here for posterity since I could not find anyone able to help me here.
First I installed Crystal Reports on the computer that was giving me the problem. (my company has a license for 2011 so I installed 2011)
Next, I opened the report (using the Crystal Reports 2011 program) and tried to preview it, it prompted me for login info so I gave the login info and let the report generate a preview.
Finally I ran the program and it worked!
So I think the problem was mostly solved by installing crystal reports, but I think it was still necessary to go into the report itself and make sure it could generate a preview.