[I am new to ADO.NET and Entity Framework, so sorry if this question seems weird.]
In my WPF application, the user can switch between different databases at runtime. When they do, I want to be able to quickly verify that the database is still available. What is easily accessible to me is ObjectContext. The testing that I am collecting is counting the total number of records in a very small table, and if it returns the results, then it passes, if I get an exception, then this will not work. I do not like this test, it seemed the simplest with ObjectContext.
I tried to set the connection timeout in the connection string and ObjectConntext and either, it seems, changed something for the first script, and the second is already fast, so it is not noticeable that it is changing anything.
Scenario 1
If the connection was disconnected when it takes about 30 seconds before the first access, before it gives me an exception that the underlying provider has failed.
Scenario 2
If the database was started when I started the application and I access it, and then the connection drops when using the test, it returns quickly and almost instantly.
I want the first scenario described to be as fast as the second.
Please let me know what is the best way to resolve this, and if there is a better way to quickly check the database connection, please let us know.