More information:
Object reference not set to an instance of an object.
-------------------
Here is the code:
public void HandleException(LogException logObject)
{
HttpContext ctx = HttpContext.Current;
bool logIt = Properties.Settings.Default.LogErrors;
int EID = -1;
if (logIt)
{
String sPageName = "";
if (ctx.Request.ServerVariables["PATH_INFO"] != null)
{
string[] str =
ctx.Request.ServerVariables["PATH_INFO"].ToString().Split('/');
sPageName = str[str.Length - 1];
}
try
{
DbCommand dbCommand =
db.GetStoredProcCommand("spInsertApplicationErrorL og");
db.AddInParameter(dbCommand, "@NBID", DbType.String,
logObject.CurrentNBID);
db.AddInParameter(dbCommand, "@ErrorMsg", DbType.String,
logObject.ErrorMsg);
db.AddInParameter(dbCommand, "@ErrorPage",
DbType.String, sPageName.ToString());
db.AddInParameter(dbCommand, "@ErrorStacktrace",
DbType.String, logObject.ErrorStack);
db.AddOutParameter(dbCommand, "@EID", DbType.Int32, 100);
EID = db.ExecuteNonQuery(dbCommand);
EID = (int)db.GetParameterValue(dbCommand, "@EID");
ctx.Session["myErrorID"] = "-1";//EID.ToString();
//if you are doing debug locally, you can comment out
sendEmail below
#if DEBUG
sendEmail(EID, logObject);
#else
sendEmail(EID, ex);
#endif
//local testing sendEmail(164, ex);
}
catch (Exception exc)
{
EventLog.WriteEntry(exc.Source, "The error cannot be
logged into DB, and it is throwed from Exception Log!",
EventLogEntryType.Error);
}
}
}
------------------------------------------------
--
Moojjoo
http://moojjoo.blogspot.com
"Moojjoo" wrote:
Quote:
From my UI > Service > BL I am creating a service that will pass exceptions
to a backend database log.
However I am returing the SCOPE_IDENTITY from the DB.
I then am attempting to create in the BL
HttpContext ctx = HttpContext.Current;
Then after the call to the DB I am attempting to set a session variable:
ctx.Session["myErrorID"] = EID.ToString();
However I am getting ctx.Session does not exsit...
Any help would be great.
--
Moojjoo
http://moojjoo.blogspot.com
|