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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:52:34+00:00 2026-05-17T15:52:34+00:00

I realize that there is no way to atomically guarantee: if(hasInternet) doDatabaseCall(); However, what

  • 0

I realize that there is no way to atomically guarantee:

if(hasInternet)
    doDatabaseCall();

However, what is the correct way of handling connection problems when dealing with DbConnection and DbCommand objects in the .NET world? I’m specifically interested in the MySqlConnection and MySqlCommand objects but assume (hope) its pattern of exceptions is the same as SQL Server’s classes.

I’d assume that if the internet goes down before calling, conn.Open(), a MySqlException gets raised. I’d also assume the same happens if you call ExecuteReader or ExecuteNonQuery and the internet has gone down.

I’m not sure because the docs for the MySql objects don’t say. The SqlServer objects just say that it might raise a SqlException which means:

An exception occurred while executing the command against a locked row. This exception is not generated when you are using Microsoft .NET Framework version 1.0.

That doesn’t seem to cover connection issues… What I’d like to do is handle the exception, wait for some amount of time, and start over again. My application’s sole purpose is to execute these database calls and its running on a dedicated system so retrying forever is really the best option I believe. That said, I would love to differentiate between connection exceptions and other kinds of database exceptions, is that possible?

I’ve done some testing and it appears to work as I assume but does it work in all edge cases? Such as: the command was successfully sent to the database server but the connection goes down before or while the results are being returned? If it doesn’t work in all edge cases then I’m going to have to: execute a command, query for the desired state change, execute the next command, etc. It’s important that each command goes through.

I am connecting to a port on localhost that is forwarded via SSH to a remote server if that makes a difference.

  • 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-17T15:52:35+00:00Added an answer on May 17, 2026 at 3:52 pm

    As for the SqlDataProvider:

    The SqlException exception has a several properties that give you detailed information why your operation failed.

    For your use case the “Class” property might be a good choice. It’s a byte indicating the severity of the exception.

    See: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.class.aspx

    If that is not specific enough, you can examine that individual errors in the Errors collection.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.errors.aspx

    Based on that information you can decide whether to retry.

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

Sidebar

Related Questions

Is there a way to mount a file for read/write access? I realize that
Of course I realize that there's no one right way to design a SQL
I realized that ShowHeaderWhenEmpty only works in PostBacks. Is there any way to make
I realize that there are many similar questions, but most involve scaling down the
I realize that since UNIX sockets are platform-specific, there has to be some non-Java
I realize that parameterized SQL queries is the optimal way to sanitize user input
After going through some examples on the web I realize that there is a
I'm using MKAnnotationView for pins & callouts and I realize that there is the
Having read some postings here about this topic, I realize that there are quite
Premise I believe that there is a way to objectively define "Good" and "Bad"

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.