Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Firstly, I have this working in development, however when I publish to the production webserver, instead of generating the report, it asks me for login credentials again.
Here is a snapshot of my entire code behind file:

C#
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if ((ViewState["ParametersShown"] != null) &&
(ViewState["ParametersShown"].ToString() == "True"))
{
ReportListing myListing = new ReportListing();
BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() + 
myListing.GetReportFileName(Session["Report"].ToString()));
}
}

protected void btnBuild_Click(object sender, EventArgs e)
{
CrystalReportViewer1.ParameterFieldInfo.Clear();
DateTime startDate = DateTime.Parse(Session["FromDate"].ToString());
DateTime endDate = DateTime.Parse(Session["ToDate"].ToString());

ParameterFields paramFields = new ParameterFields();
ParameterField crStartDate = new ParameterField();
ParameterField crEndDate = new ParameterField();
crStartDate.Name = "@StartDate";
crEndDate.Name = "@EndDate";
ParameterDiscreteValue dcrStartDate = new ParameterDiscreteValue();
ParameterDiscreteValue dcrEndDate = new ParameterDiscreteValue();
dcrStartDate.Value = startDate;
dcrEndDate.Value = endDate;
crStartDate.CurrentValues.Add(dcrStartDate);
crEndDate.CurrentValues.Add(dcrEndDate);
paramFields.Add(crStartDate);
paramFields.Add(crEndDate);

ReportListing myListing = new ReportListing();
BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() + 
myListing.GetReportFileName(Session["Report"].ToString()));
CrystalReportViewer1.ParameterFieldInfo = paramFields;
ViewState["ParametersShown"] = "True";
ViewState["ReportName"] = Session["Report"].ToString();
}
private void BindReport(string FilePath)
{
ReportDocument Report = new ReportDocument();
Report.Load(FilePath);
SetTableLocation(Report.Database.Tables);
CrystalReportViewer1.ReportSource = Report;
}
private void SetTableLocation(Tables tables)
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = ConfigurationManager.AppSettings["ReportDBServerName"].ToString();
connectionInfo.DatabaseName = ConfigurationManager.AppSettings["ReportDBDBName"].ToString();
connectionInfo.UserID = ConfigurationManager.AppSettings["ReportDBUserID"].ToString();
connectionInfo.Password = ConfigurationManager.AppSettings["ReportDBPassword"].ToString();
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogOnInfo);
}
}
}

As detailed above, running from a local machine it works fine. It is only when published to production server it asks for login details. Login details are stored in the web.config file and are correct.
Please help!
Thanks

[Moved from Answers]

Yes, Anonymous access is enabled and it has suitable permissions on the folder. The credentials it is asking for is the database credentials. When working on development server it was pointing at the same database, but since publishing to production, it asks for database login credentials. Also (rather weirdly), it won't let me type in database name when asked for the credentials either.
If I run exactly the same application from my development machine it correctly passes the DB parameters and login info, thus bypassing the DB login screen correctly. I can see no legitimate reasoning for this behavior.

Solution

I have resolved this. Problem is that it uses the SQL Native Client, which is not installed on the production server. I have since installed this and all is working.
Posted
Updated 8-Oct-10 6:50am
v3

Have you enabled anonymous access under authentication method for that site / directory in IIS?

I don't think crystal report asks for login credentials as its UserID and Password is for accessing database not page
 
Share this answer
 
Great that you figured it out ;)
such issues are really very hard to point in production servers.:thumbsup:
 
Share this answer
 
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("CrystalReportByAgents.rpt"));
crystalReport.SetDatabaseLogon("LoginId", "Password", @"SYSTEM\SQLEXPRESS", "databaseName");

CrystalReportViewer1.ReportSource = crystalReport;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900