hello i am using following code of mudassir to save the error in database
i am using this in global asax page, this works fine, the only problem is that it shows in db "object reference not set to an instance of an object" that is fine, but can i trace on which page that error occured what should i modify in the below code to take page url of the error.
please advice
string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
string sqlStatment = "INSERT INTO ErrorLog VALUES(@Date,@Message)";
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr))
{
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlStatment, con))
{
con.Open();
cmd.Parameters.AddWithValue("@Date", DateTime.Now);
cmd.Parameters.AddWithValue("@Message", ((System.Exception)(Server.GetLastError().InnerException)).Message.Trim());
cmd.ExecuteNonQuery();
con.Close();
}
}