c# - Testing an Entity Framework database connection -
i have app connects mysql database through entity framework. works 100% perfectly, add small piece of code test connection database upon app startup.
i had idea of running tiny command database , catching exceptions, if there problem (eg app.config missing or database server down) app takes huge amount of time run code , throw exception (~1 min). imagine due connection timeouts etc have fiddled such properties no avail.
would able assist ideas go?
are wanting see if db connection valid. if take @
using (databasecontext dbcontext = new databasecontext()) { dbcontext.database.exists(); }
http://msdn.microsoft.com/en-us/library/gg696617(v=vs.103).aspx ef5 https://msdn.microsoft.com/en-us/library/gg696617(v=vs.113).aspx ef6
and checking if server machine up, db server or web services server , try this:
public pingreply send( string hostnameoraddress )
Comments
Post a Comment