I want to handle any Oracle Db Exception on Application level.Hence written following piece of code in Application_Error function of Global.asax
The code seems to be more specific but i want to write code for any kind of Oracle Exception.
protected void Application_Error(object sender, EventArgs e)
{
var isOracleException = false;
//Get the error details.
Exception lastException = Server.GetLastError();
if (lastException != null)
{
if (lastException.Message.StartsWith("ORA"))
{
isOracleException = true;
}
}
HttpContext httpContext = (sender as MvcApplication).Context;
httpContext.ClearError();
httpContext.Response.Clear();
httpContext.Response.TrySkipIisCustomErrors = true;
RouteData routeData = new RouteData();
if (isOracleException)
{
routeData.Values["controller"] = "HandleError";
routeData.Values["action"] = "Error";
IController errorController = new HandleErrorController();
var requestContext = new RequestContext(new HttpContextWrapper(httpContext), routeData);
errorController.Execute(requestContext);
}
}
Can we access OracleException Class in Global.asax file ?
You can check if the exception is an
OracleExceptionby usingisoras:Or: