How do I gracefully handle errors when trying to connect to a database that may be down, or given an incorrect connection string in MVC 4?
I have my string in Web.config and the way it accesses the database is just instantiating my class derived from DBContext in each controller, like so:
private DBEntities db = new DBEntities("database");
This works fine if the database is up and everything is correct, but if it's not, the pages on my web site display this error:
Exception Details: System.ComponentModel.Win32Exception: The network path was not found
Obviously I don't want this to appear, what I'd like to do is have a way to try catch the error and display a custom error page (similar to 404 Page Not Found).
Thank you.