Try our conversational search powered by Generative AI!

How to handle SQL Server Exceptions in Episerver

Vote:
 

Hi,

I am handling episerver application exceptions in global.asax file. Whenever any exception occur it redirects to 404 error page and exception get log in text file.

But when the SQL server is down it shows an sql server exception on page and does not redirect it to error page.

So how can I handle such types of exceptions in episerver.

Example of SQL server exception 

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

#181457
Edited, Aug 21, 2017 14:12
Vote:
 

<customErrors> ?

#181460
Aug 21, 2017 14:27
Vote:
 

As Valdis are saying the best way to handle this is in web.config with customerrors and httperrors.

https://docs.microsoft.com/en-us/iis/configuration/system.webserver/httperrors/

#181465
Aug 21, 2017 15:31
Vote:
 

Hello,

Is there any different option other than custom error.

#181480
Aug 22, 2017 9:47
Vote:
 

can try to subscribe to unhandled exceptions in global.asax

#181482
Aug 22, 2017 9:52
Vote:
 

Why do you not want to use the built in and proved effective solution with httperrors?

#181483
Aug 22, 2017 9:58
Vote:
 

Hello,

As such there is no issue in using built in solution.

Actullay I am handling exception in global.asax file like

protected void Application_Error(object sender, EventArgs e)
{
//Get error page url
var baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/');
var contentReference = new ContentReference(2664);
var url = ServiceLocator.Current.GetInstance<IContentRepository>().Get<CustomErrorPage>(contentReference).LinkURL;
var completeUrl = baseUrl + url;

//Global Exception handling
Exception exception = Server.GetLastError();
Server.ClearError();
Logger.Error(exception);
Response.Redirect(completeUrl);
}

I am to handle all exception but If server is down then this approach gets fail.

Any ways I can go with customErrors approach also.

#181486
Aug 22, 2017 11:12
Vote:
 

"server is down"? you mean no network access for it? there is great magnitude of edge cases what could possibly go wrong and how to hande.

#181493
Aug 22, 2017 13:26
Vote:
 

Your biggest problem is that you are trying to show a Episerver page when you get an error and for examle if the SQL is down, this line will throw it's own error since it can not talk to the database.

var url = ServiceLocator.Current.GetInstance<IContentRepository>().Get<CustomErrorPage>(contentReference).LinkURL;

A page for 500-error should never be a dynamic page, it should always be static.

#181495
Aug 22, 2017 13:58
Vote:
 

@Valdis Iljuconoks and @Henrik Fransas.

Okay,  I understood, thank you.

#181496
Aug 22, 2017 14:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.