Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 566021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:56:02+00:00 2026-05-13T12:56:02+00:00

[ I am new to ADO.NET and the Entity Framework, so forgive me if

  • 0

[I am new to ADO.NET and the Entity Framework, so forgive me if this questions seems odd.]

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 quick 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.

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.

Scenario One

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.

Scenario Two

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.

I want the first scenario described to be as quick as the second one.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:56:02+00:00Added an answer on May 13, 2026 at 12:56 pm

    There really is no easy or quick way to resolve this. The ConnectionTimeout value is getting ignored with the Entity Framework. The solution I used is creating a method that checks if a context is valid by passing in the location you which to validate and then it getting the count from a known very small table. If this throws an exception the context is not valid otherwise it is. Here is some sample code showing this.

    public bool IsContextValid(SomeDbLocation location)
    {
        bool isValid = false;
    
        try
        {
            context = GetContext(location);
            context.SomeSmallTable.Count();
            isValid = true;                
        }
        catch
        {
            isValid = false;
        }
    
        return isValid;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ADO.NET Entity framework for my project and I am new at this
My WPF desktop-based application uses ADO.Net Entity Framework in order to connect to SQL
I develop desktop-based WPF-application, that uses SQL Server 2008 R2 Database and ADO.NET Entity
In my new project I am asked to use ADO.NET Entity framework and WCF
I am accessing my database through ADO.NET Entity framework in MVC 3 Application. I
I am very new to ADo.net entity framework and i am getting the following
I'm trying to add a new ADO.Net Entity Data Model to an MVC project
ADO.NET has the notorious DataRow class which you cannot instantiate using new. This is
I am stating out with entity framework. I have created my ADO.NET Entity Model
Good day! Despite the fact LINQ2SQL and ADO.NET Entity Framework exists there were situations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.