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 1000939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:35:29+00:00 2026-05-16T07:35:29+00:00

Consider a simple setup: // _conn is the OdbcConnection with a MySQL-Server (MySQL-Connector 3.51)

  • 0

Consider a simple setup:

// _conn is the OdbcConnection with a MySQL-Server (MySQL-Connector 3.51)
// _cmd is a created OdbcCommand

// Constructor has created the objects successfully

public void DoSomething() {
    if(_conn.State == ConnectionState.Open)
        _cmd.ExecuteNonQuery();
}

Now my problem is, that OdbcConnection.State isn’t reliable. The thing is that after some time the connection gets lost, but the State-Property doesn’t know anything about it and keeps telling me that the connection is open at least till the point were I try to execute a command (which fails gracefully). I even had the situation were the State-Property would never refresh and kept telling me that the connection was still there (but commands failed).

Of course I could add Try {...} Catch {...} blocks to my code, but I tried to avoid them because extending a two-line function with at least four lines of error handling is a little bit…heavy.

So my question is: Why isn’t OdbcConnection.State reliable and can I fix it?

  • 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-16T07:35:30+00:00Added an answer on May 16, 2026 at 7:35 am

    The nature of networking is that you often don’t know there’s a problem until you actually try to send data. If you simply pull the plug out of the back of the computer (or you pull the plug out of a switch somewhere in between your client and the server) then there’s no way for the operating system to know until it actually tries to send data that there’s even a problem.

    The reason, then, that State is not reliable is because it’s impossible to make it completely reliable without actually actually trying to send data to the server. Since that’s far too much work for a simple property to do (a whole network roundtrip) it doesn’t do that, and just does the simplest thing possible.

    Also, there’s the fact that there’s a race condition between when you call State == Open and actually executing the command: you might call State == Open, and then someone pulls the plug before you execute the command.

    So at the end of the day, you’re going to have to have that exception handler anyway. I would also suggest that you don’t put the exception around every single call to the database. If you’re doing a website, then have a page-level handler and leave it at that. There’s really no point trying “handle” a database going down in any other way than by displaying an error message to the user anyway…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a simple table with an auto-increment column like this: CREATE TABLE foo (
Consider the following simple C program that read a file into a buffer and
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider an indexed MySQL table with 7 columns, being constantly queried and written to.
Consider this sample code: <div class=containter id=ControlGroupDiv> <input onbeforeupdate=alert('bingo 0'); return false; onclick=alert('click 0');return
Consider the need to develop a lightweight desktop DB application on the Microsoft platforms.
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
Consider this problem: I have a program which should fetch (let's say) 100 records
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider the Oracle emp table. I'd like to get the employees with the top

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.