Results 1 to 7 of 7

Thread: [RESOLVED] Weird error right after the db server goes up after being down.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    124

    Resolved [RESOLVED] Weird error right after the db server goes up after being down.

    Hi,

    So I have a TableAdapter (created by the designer) that fills a table like this.

    Code:
    Try
    	cmd.Connection.Open()
    	MyTableAdapter.Fill(MyDataSet.MyTable)
    	cmd.Connection.Close()
    Catch ex As Exception
    	cmd.Connection.Close()
    	Throw
    End Try

    When the db server is up it works fine.
    When the db server is down it gives out this error:

    MySqlException was caught:
    Unable to connect to any of the specified MySQL hosts.


    Which is fine too as it's expected.

    The problem is when the server goes down and the above error gets thrown and then the server goes up again. When the code gets executed then it gives out this error:

    MySqlException was caught:
    Fatal error encountered during command execution.


    This error happens only the first time the code executed right after the server goes up. When it gets executed the second time (and all the times that follow) it works fine. Which is wired.

    Any enlightenment would be very appreciated.

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,035

    Re: Weird error right after the db server goes up after being down.

    I'm not on a VS PC right now but it may be an issue of the server awaken after the shutdown.
    In that case, i believe there is a cmd.timeout or cmd.commandtimeout? Maybe give it a value depending on how fast the error happens.
    So let's say it happens in 0,2 sec, then give it a value of 500.
    I haven't use MySql so this is just a guess.
    .

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    124

    Re: Weird error right after the db server goes up after being down.

    Quote Originally Posted by sapator View Post
    I'm not on a VS PC right now but it may be an issue of the server awaken after the shutdown.
    In that case, i believe there is a cmd.timeout or cmd.commandtimeout? Maybe give it a value depending on how fast the error happens.
    So let's say it happens in 0,2 sec, then give it a value of 500.
    I haven't use MySql so this is just a guess.
    Thanks for the guess but I don't think it's about the timeout. I manually reproduced the error. I shut down the server and let it shut for say 3 minutes and then start it again and let it say for 3 minutes then I execute the code and it gives the same weird error the first time I execute it. My users don't see the error of course as it's being trapped but they always have to click the button twice to get it to work which is annoying.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,489

    Re: Weird error right after the db server goes up after being down.

    Just because the server is back online doesn't mean the service is back online. I've got a docker container that runs an oracle database, the container itself only takes a minute or two to come online, but it takes 5 minutes for the database and the listener to come online. What happens if you wait 5 or 10 minutes?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: Weird error right after the db server goes up after being down.

    Not related to your issue but that code needs changing. Firstly, closing the connection in both the Try and Catch blocks is wrong. You should only be closing once, in a Finally block. Finally exists specifically to do cleanup that need to be done whether an exception is thrown or not, e.g. closing a connection. If you really are doing nothing else in the Catch block but rethrowing, the Catch block is pointless:
    vb.net Code:
    1. Try
    2.     cmd.Connection.Open()
    3.     MyTableAdapter.Fill(MyDataSet.MyTable)
    4. Finally
    5.     cmd.Connection.Close()
    6. End Try
    More than that though, unless there are actually other database operations in the Try block as well, there's no need or point to explicitly opening and closing the connection. The Fill method will do it implicitly so you can get rid of all that code other than the Fill call:
    vb.net Code:
    1. MyTableAdapter.Fill(MyDataSet.MyTable)
    That is functionally equivalent to the code you have.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    124

    Re: Weird error right after the db server goes up after being down.

    Quote Originally Posted by techgnome View Post
    Just because the server is back online doesn't mean the service is back online. I've got a docker container that runs an oracle database, the container itself only takes a minute or two to come online, but it takes 5 minutes for the database and the listener to come online. What happens if you wait 5 or 10 minutes?

    -tg
    Hi tg, I appreciate your input.
    I started the server and waited for 15 minutes; the problem persists!
    If the operation just fails forever it would be easier. But it fails the first time only and then works just fine the next time and that's what makes it very weird to me.

    I'd like to add something; It happens only in the .NET project and with the TapleAdapter specifically. I tried in MySql Workbench CE and with a simple MySqlCommand.ExecuteNonQuery method within my .NET project and it works fine. No errors whatsoever!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    124

    Re: Weird error right after the db server goes up after being down.

    Hello John,
    As you have noticed, the code snippet above was taken from a larger region of my code that has other db operations. I gave you the code snippet and removed the other operations where I have to use MySqlCommand.ExecuteNonQuery method which needs to open a connection first (e.g. to check for the server app version and force my users to update theirs).

    Well, The connection I use with these operations is the same one the TapleAdapter use. I always open it, do some other db operations, and then I call the TableAdapter Fill method and then I close the connection. This has never caused a conflict before, but not this time. But after what you said about the non-necessity of opening a connection for the TableAdapter and although I don't open it for the TableAdapter but for the other db operation I got extremely specious, so, I followed your tips, and declared a new connection/mysqlcommand for the other operations, and guess what? The TapleAdapter worked from the first time and the error disappeared.

    Oh my God John! that was a non related input and it has fixed my problem, what if it was related! Thank you, Thank you, Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width