Dear All,
error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
sales_order_report.Page_Load(Object sender, EventArgs e) +2610
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
how can i solved this error ?
it is perfct run on my local server but when i publish the website and upload on server this error will come. i use below code for the crystal report in asp.net c#
i use below.
Class1 c = new Class1();
ReportDocument cr;
MailMessage msg;
string id ="", del_id ="",path ="";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] == "" || Session["user"] == null)
{
Response.Redirect("default.aspx");
}
if (!IsPostBack)
{
try
{
id = Request.QueryString["id"];
del_id = Request.QueryString["del_id"];
c.setcon();
string s = "select id,dealer_order_no,dealer,dealer_id,dealer_name,order_date,product_name,packing,qty,unit,rate,required_date,amount,remarks,file_path from sales_order where dealer_id='" + del_id + "'";
SqlDataAdapter ad = new SqlDataAdapter(s, c.getcon());
DataSet ds = new DataSet();
ad.Fill(ds);
path = Server.MapPath("REPORTS/sales_order.rpt");
cr = new ReportDocument();
cr.Load(path);
cr.SetDataSource(ds);
cr.SetParameterValue(0, del_id);
CrystalReportViewer1.ReportSource = cr;
CrystalReportViewer1.DataBind();
string order_file = string.Empty;
order_file = Server.MapPath("SALES_ORDER/purchase_order.pdf");
cr.ExportToDisk(ExportFormatType.PortableDocFormat, order_file);
string email_id = string.Empty, email_password = string.Empty;
c.setcon();
string email_setting = "select email_id,password from send_email";
SqlDataAdapter email_adapter = new SqlDataAdapter(email_setting, c.getcon());
DataSet email_dataset = new DataSet();
email_adapter.Fill(email_dataset);
c.close();
if (email_dataset.Tables[0].Rows.Count != 0)
{
email_id = email_dataset.Tables[0].Rows[0][0].ToString();
email_password = email_dataset.Tables[0].Rows[0][1].ToString();
}
ArrayList region_email = new ArrayList();
string region_email_address = "select email,region_email,name from empl where id='" + ds.Tables[0].Rows[0][2].ToString() + "'";
SqlDataAdapter region_ad = new SqlDataAdapter(region_email_address, c.getcon());
DataSet region_ds = new DataSet();
region_ad.Fill(region_ds);
string[] region;
string dealer_email = string.Empty;
dealer_email = region_ds.Tables[0].Rows[0][0].ToString();
string[] split = region_ds.Tables[0].Rows[0][1].ToString().Split(',');
region = new string[split.Length];
for (int i = 0; i < split.Length; i++)
{
region[i] = System.Convert.ToString(split[i]);
}
string[] cc_mail;
cc_mail = new string[2];
for (int h = 0; h < cc_mail.Length - 1; h++)
{
cc_mail[h] = dealer_email;
}
cc_mail[1] = "miteshmachhi1014@yahoo.com";
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.Credentials = new NetworkCredential(email_id, email_password);
client.EnableSsl = true;
MailAddress from = new MailAddress(email_id);
msg = new MailMessage();
msg.From = from;
foreach (string regionwise_email in region)
{
msg.To.Add(regionwise_email);
}
foreach (string cc_email_Send in cc_mail)
{
msg.CC.Add(cc_email_Send);
}
string message = " Please find attached herewith Purchase Order sent by " + region_ds.Tables[0].Rows[0][2].ToString() + " from FFW.";
msg.Subject = "Purchase Order - " + region_ds.Tables[0].Rows[0][2].ToString();
msg.Body = message;
msg.Attachments.Add(new Attachment(order_file));
if (!(ds.Tables[0].Rows[0][14].ToString().Equals("")))
{
string files = string.Empty;
files = Server.MapPath("PURCHASE_ORDER_FILES/" + ds.Tables[0].Rows[0][14].ToString());
cr.ExportToDisk(ExportFormatType.PortableDocFormat, files);
msg.Attachments.Add(new Attachment(files));
}
client.Send(msg);
c.close();
string s1 = "yes";
Response.Redirect("place_your_order.aspx?order=" + s1 + "");
}
catch (Exception e1)
{
e1.Message.ToString();
}
finally
{
cr.Close();
}
}
}