I know this question has been asked but I don't see anything that helps me. What I have is a ticket application that records trouble tickets then sends an email to the right person. When I run this on my machine it works, but on my server I get a Null object reference error.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Oracle.DataAccess.Client;
using System.Text;
using System.Data.OleDb;
using System.Window开发者_JAVA百科s.Forms;
using System.IO;
using System.Diagnostics;
using System.Net.Mail;
namespace Ticketing {
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
"201157";
}
protected void btn_submit_Click(object sender, EventArgs e)
{
DateTime dtnow = DateTime.Now;
OracleConnection conn = new OracleConnection(Global.oracle);
conn.Open();
StringBuilder sqls = new StringBuilder("Insert statment")
OracleCommand cmd = new OracleCommand(sqls.ToString(), conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(":REASON", txt_reason.Text);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
// end insert
System.Threading.Thread.Sleep(2000);
btn_refresh_Click(null, null);
btn_email_Click(null, null);
//send email
MailMessage mail = new MailMessage();
mail.From = new MailAddress("email@email.com");
if (dd_urgency.SelectedValue.ToString() == "Critical")
{
mail.To.Add("email@email.com");
mail.To.Add("email@email.com");
mail.To.Add("email@email.com");
mail.To.Add(lbl_email.Text);
}
else if (dd_urgency.SelectedValue.ToString() == "Urgent")
{
mail.To.Add("email@email.com");
mail.To.Add("email@email.com");
mail.To.Add("email@email.com");
mail.To.Add(lbl_email.Text);
}
else if (dd_urgency.SelectedValue.ToString() == "Normal")
{
mail.To.Add("email@email.com");
mail.To.Add(lbl_email.Text);
if (dd_location.SelectedValue.ToString() == "XL")
{
mail.To.Add("email@email.com");
}
}
else if (dd_urgency.SelectedValue.ToString() == "None")
{
mail.To.Add("email@email.com");
mail.To.Add(lbl_email.Text);
if (dd_location.SelectedValue.ToString() == "XL")
{
mail.To.Add("email@email.com");
}
}
mail.IsBodyHtml = true;
mail.Subject = ("Ticket Id " + (label_id.Text) +" Urgency: " + dd_urgency.SelectedValue.ToString()) + " At " + (dd_location.SelectedValue.ToString());
mail.Body = txt_reason.Text;
SmtpClient smtp = new SmtpClient("basic.smtp.ttu.edu");
try
{
smtp.Send(mail);
}
catch (SmtpException ex)
{
Response.Write("<script>alert('There has been an error please call Travis Jorge at ')</script>");
}
// this.Session.Abandon();
Response.Write("<script>alert('You have submitted your trouble ticket we will be right with you. If you need immediate assistance contact Travis Jorge.')</script>");
txt_reason.Text = "";
// lbl_email.Text = "";
label_id.Text = "";
dd_location.SelectedIndex = 0;
dd_urgency.SelectedIndex = 0;
}
protected void btn_refresh_Click(object sender, EventArgs e)
{
OracleConnection conn1 = new OracleConnection(Global.oracle);
conn1.Open();
StringBuilder sqls1 = new StringBuilder(Select statement)
OracleCommand cmd1 = new OracleCommand(sqls1.ToString(), conn1);
cmd1.CommandType = CommandType.Text;
OracleDataReader dr = cmd1.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
if (!dr.IsDBNull(0))
{
label_id.Text = dr.GetDecimal(0).ToString();
}
}
cmd1.Dispose();
conn1.Close();
}
protected void btn_email_Click(object sender, EventArgs e)
{
//Select email for return email
OracleConnection conn2 = new OracleConnection(Global.oradb);
conn2.Open();
StringBuilder sqls2 = new StringBuilder(select statement)
OracleCommand cmd2 = new OracleCommand(sqls2.ToString(), conn2);
cmd2.CommandType = CommandType.Text;
OracleDataReader dr2 = cmd2.ExecuteReader();
dr2.Read();
if (dr2.HasRows)
{
if (!dr2.IsDBNull(0))
{
lbl_email.Text = dr2.GetString(0).ToString();
}
}
cmd2.Dispose();
conn2.Close();
}
}
}
I can tell you that all the SQL statements work and this code runs fine on my server without the btn_email function and its associated commands. Any help would be appreciated. Also I know that all the values requested for the objects are available to the page.
Check if you have mailSettings in your web.config file.
<system.net>
<mailSettings>
<smtp>
<network
host="smtp.yourmailserver.com"
port="25" />
</smtp>
</mailSettings>
</system.net>
精彩评论