try catch Error send mail in asp.net :
Syntex :
try
{
......
... // ex: Connection Open and Insert......
}
catch(Exception ex)
{
// Error Catch
}
finallly
{
// Connection Close
}
aspx.cs :
NameSpace :
using System.Web.Mail; // mail send Add Namespace
protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
try //
{
Insert= "Insert Into Registration(UserName,Salary)
va
lues('" + UserName "','" + Salary+ "')";
Conn.open(); // ex: Connection Open
Cmd = new SqlCommand(Insert, Conn);
Cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Email ErrorMail = new Email(); //NameSpace Use
ErrorMail .From = "noreply@123.com"; // From Mail
ErrorMail .To = "123@gmail.com"; // To Mail
ErrorMail .Subject = "Error Message"; //Subject
ErrorMail .Message =
"Error URL : " + Request.Url.AbsoluteUri+ "
//Err URL Get
"Time : " + System.DateTime.Now.ToString() + "
//Err DateTime
"Error Message :" + ex.Message+ "
//Err ex Message
"stack Trace :" + ex.StackTrace + ";
//Err StackTrace PathofTheFolder
Email .SendMail(ErrorMail );
// Send Mail
}
finally
{
Conn.Close();
}
}
Error Mail:
Error URL : http://www.123.com/123/Register.aspx // Page Error URL
Time : 6/13/2013 5:15:57 AM // Error URL DateTime
Error Message : Object reference not set to an instance of an object. // Error Type
stack Trace : at Register Page_Load(Object sender, EventArgs e) in c:\inetpub\123.com\123\456\Register.aspx.cs:line 38
Time : 6/13/2013 5:15:57 AM // Error URL DateTime
Error Message : Object reference not set to an instance of an object. // Error Type
stack Trace : at Register Page_Load(Object sender, EventArgs e) in c:\inetpub\123.com\123\456\Register.aspx.cs:line 38
//Error Page Path and Page Name and Line NO
No comments:
Post a Comment