I am facing error in Crystal Report Preview.
error: Object reference not set to an instance of an object
It is working fine on local machine but not working on server side.
C#
SqlConnection con = new SqlConnection();
ReportDocument rpt = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack)
{
rpt.Dispose();
rpt.Close();
loadReport();
}
}
private void loadReport()
{
rpt.Dispose();
rpt.Close();
con = new SqlConnection("Data Source=SERVER1\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ucms;MultipleActiveResultSets=True;");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("sp_bigbaleprint", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@BID", Request.QueryString["BID"]);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
rpt.Load(Server.MapPath("~/CRBB.rpt"));
rpt.SetDataSource(ds.Tables["Table"]);
BBPViewer.ReportSource = rpt;
rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, false, "Bigbalprd");
}
catch (Exception ex)
{
rpt.Close();
rpt.Dispose();
con.Close();
}
}
protected void CRBigview_Unload(object sender, EventArgs e)
{
if (rpt != null)
{
rpt.Close();
rpt.Dispose();
}
}