Relaunch a function

Hi all!
I’m thinking about a generic problem I have. Here the scenario…

My desktop app connects to a remote database server when I open it, and close the connection when it quits. Sometimes internet connection may be off for a little bit, so my app has to connect again to the server.

So I have an idea to avoid to quit and relaunch the app: if there is a socketerror, I have to retry the server connection. And this is done now, but (and here my troubles) the app have to execute again the query that before have generated the error.

And here the solution, but I don’t know if (and how) may be applicable: I have a “reconnectdb()” function that I “call” when I have a connection error, but the reconnectdb() (at its end) have to relaunch the method that called it…

For example: the method “searchinvoices” fails and when it “catch” the error can call reconnectdb() and when reconnectdb gains again the connection, it have to call again “searchinvoices”… and again… the method “listcustomers” fails and when it “catch” the error can call reconnectdb() and when reconnectdb gains again the connection, it have to call again “listcustomers”…

I hope I’ve explained well my idea… Anyone has suggestions?

Thanks a lot!!!

You could use something like this

DIM methods() As Introspection.MethodInfo = Introspection.GetType(self).GetMethods
for each method As Introspection.MethodInfo in methods
  if (method.Name = "moo") then
    method.Invoke self
    exit for
  end if
next method

replace self with the class that has your method
replace moo with the name of your method

1 Like

I place all my database calls in routines that check for errors. If there’s an error, attempt to reconnect, then run the query again. I posted some sample code in an old topic. There are also some other ideas there.

1 Like