title: Quickly Testing Database Connectivity within the Entity Framework
body: <p>[<em>I am new to ADO.NET and the Entity Framework, so forgive me if this questions seems odd.</em>]</p>
  
  <p>In my WPF application a user can switch between different databases at run time.  When they do this I want to be able to do a <strong>quick</strong> check that the database is still available.  What I have easily available is the ObjectContext. The test I am preforming is getting the count on the total records of a very small table and if it returns results then it passed, if I get an exception then it fails.  I don't like this test, it seemed the easiest to do with the ObjectContext.</p>
  
  <p>I have tried setting the connection timeout it in the connection string and on the ObjectConntext and either seem to change anything for the first scenario, while the second one is already fast so it isn't noticeable if it changes anything.</p>
  
  <p><strong>Scenario One</strong>
  <p>
  If the connect was down when before first access it takes about 30 seconds before it gives me the exception that the underlying provider failed.  </p>
  
  <p><strong>Scenario Two</strong>
  <p>
  If the database was up when I started the application and I access it, and then the connect drops while using the test is quick and returns almost instantly. </p>
  
  <p>I want the first scenario described to be as quick as the second one.  </p>
  
  <p>Please let me know how best to resolve this, and if there is a better way to test the connectivity to a DB quickly please advise.</p>