Connection Lost Error

i have a desktop application and i am using mysql database.
Database connection was working fine till database was on my local machine.
now i moved it to Go Daddy server, after moving i am able to connect using application but gets disconnected after some time.
If i add db.Connect method then it works fine.
My problem is i can’t add this statement every where in code.
Does anyone know why i am getting disconnected ?
Is there anything i am missing?
And it is possible to add db.Connect method in a particular event so that don’t need at all locations

Many possibilities, one usual is being idle too much time (a number of seconds set in server) without sending new queries. The server drops your connection because you could have left… and it needs its resources back ASAP.

You should have a method used everywhere in your code, and you should just adjust such method.

As @Rick_Araujo said, most probably a Timeout.

I use a Class in my App which keeps Track of my Connections and has it’s own idle Time counter. It does not connect again if a Timer runs out, but “knows” that it has to connect before a connection can be used again. Because of this, my Class also has to handle the Querries. It opens, re-opens or just uses a connection for the current querry, based uppon the idle Timer and a few other parameters like concurrent connections, running Threads and more.

It’s complex but it works flawless. But i can’t offer code here, just ideas. :frowning:

One way of handling the issue is having 2 methods, and you choose one as needed, one do a “raw query” (use it inside transactions, because if you lose a connection inside the transaction, your transaction is gone anyway), the other do a “safer query” to use in atomic parts. The safer one casts a query and reads the error code if there’s one, if the error code is due “unconnected” reasons, reconnect and redo once. This way it works a bit faster than trying to reconnect every time even being connected, it avoids a “server ping”.