I developed a Crystal report on my local machine and I can render the report on my local website using .ExportToHttpResponse but as soon as I move my code to the production server I get a "Database logon failed" error. I basically used a .XML dataset file as the source to develop the report locally. This was my code:
I call a method to render the report:
private void RenderCrystalReports(string rptName, string pdfReportName, DataSet dataForReport)
{
string reportPath = Server.MapPath(@"\App_Data\Reports\" + rptName);
ReportDocument report = new ReportDocument();
report.Load(reportPath, OpenReportMethod.OpenReportByTempCopy);
SetDBLogonForReport(ref report);
report.SetDataSource(dataForReport);
SetDBLogonForReport(ref report);
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, true, pdfReportName);
}
and to get the dataset I have:
private DataSet GetReportData(DateTime from, DateTime to, int userID, bool totalsOnly)
{
DataTable Job = _reportRepository.GetAccountHistoryJob(from, to, userID, totalsOnly);
Job.TableName = "Accounts";
DataSet ds = new DataSet("AccountsDS");
ds.Tables.AddRange(new DataTable[] { Job });
return ds;
}
and as far as I am concerned the method below is what is supposed to help me to connect to the remote SQL server:
private void SetDBLogonForReport(ref ReportDocument reportDocument)
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString());
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.DatabaseName = builder.InitialCatalog;
connectionInfo.UserID = builder.UserID;
connectionInfo.Password = builder.Password;
connectionInfo.ServerName = builder.DataSource;
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
Why does this not work? I just figured out that even locally the .xml dataset is used so how do I use the sql dataset that I get?