Nalin Aggarwal

Nalin Aggarwal

  • NA
  • 1
  • 814

Crystal report Code is not working

Dec 23 2014 1:53 PM
When I am running the below code on local database and exporting it to pdf, it's working fine but at the time when I connecting the database online it's neither showing the result and again & again showing the LogOn screen.In this using the dynamic parameters of crystal report.
string conn_string = string.Empty;
ReportClass rc;
NameValueCollection plist;
string reportName;
string proc;

protected void Page_Load(object sender, EventArgs e)

{
conn_string=
ConfigurationManager.ConnectionStrings["sapphiredbConnectionString"].ConnectionString; NameValueCollection pList = new NameValueCollection(); reportName=Request.QueryString["Report"];
pList
= (NameValueCollection)Session["Parameter1"];
proc
= Request.QueryString["data"];

if (!IsPostBack)
LoadReport(reportName, pList, proc);

}

public void LoadReport(string reportName, NameValueCollection pList, string proc)
{
rc
= new ReportClass();
rc
.FileName = Server.MapPath(reportName);
IMConnectionInfo info = new IMConnectionInfo(conn_string);
foreach (CrystalDecisions.CrystalReports.Engine.Table mytable in rc.Database.Tables)
{
TableLogOnInfo myLoginfo = new TableLogOnInfo();
myLoginfo.ConnectionInfo.ServerName = info.ServerName; myLoginfo.ConnectionInfo.IntegratedSecurity = info.IntegratedSecurity; myLoginfo.ConnectionInfo.DatabaseName = info.DatabaseName;
if (!info.IntegratedSecurity)
{
myLoginfo.ConnectionInfo.UserID = info.UserName;
myLoginfo.ConnectionInfo.Password = info.Password;

}
mytable
.ApplyLogOnInfo(myLoginfo);
}

foreach (ParameterField pf in rc.ParameterFields)
{
ParameterDiscreteValue pdv = new ParameterDiscreteValue();
if (plist != null)
{
foreach (string k in plist.Keys)
{
if (k == pf.Name)
{
pdv
.Value = plist.Get(k);
pf.CurrentValues.Add(pdv);
} } } }
CrystalReportViewer1.ReportSource = rc;
CrystalReportViewer1.ShowAllPageIds = true;
CrystalReportViewer1.Visible = true;

}