Jump to content
dlucic

Reconnect TSQLConnection after lost wifi signal

Recommended Posts

I have a problem when my andoroid device lost wifi and connection broke. I can not reestablished that in ordinary maner. My andorid application have TSQLConnection object that connects to DataSnap server application. Everything works fine until I issue network problem. When wifi temporarly lost connection TSQLConnection also lost connection and I get Socket error #103 when I try to open TClientDataSet and that is OK. When I try it once again it works fine. I supose my application successfuly reconnect and open the query. But when I tryed it for the third time I have Socket error # 104. And again. Once OK another time Socket error #104. There is no problems when wifi connection is stable.
What should I do?

Share this post


Link to post

It is better to use a HTTP-/Rest-Server ...

 

You could easily fill a client dataset on client in this way: On Server you make a Query and then via a provider you load it into a clientdataset. Out of that you can use a command to make XML or JSON of it. That XML/JSON you send (as a result of a get query from client) to the client and with a command you can generate a filled ClientDataSet on Client and work then with that.

 

The other way, to update the database on server, could be a little bit more complex.

 

Edited by Olli73

Share this post


Link to post

Thank you but you did not understand me. I mada both server DataSnap service and client Android application. Datasnap service has connection to MS SQL Server. This is objects that I used on server side service application :

 

image.png.fe2a35734b9c742c2f9dca15141f7b25.png       image.png.3b5c94d7264f736611e907ff70fdea7e.png        

 

On the other side, I have android application that connect's to my DataSnap server service through TSQLConnection and TDSProviderConnection. And everything works fine until I lost my wifi connection in a second. I am trying to find way to recover my android application without restarting it. 

 

image.png.54abeceebe4cef310f589e7e8b8f1e6e.png

 

So, my android appllication works fine and when wifi connection broke for a second I receive Socket error #103 when I try to open one of mine TClientDataSet's. If I try it one more time it works fine again. But when I try it for the third time I receive Socket error #104. And that goes in a round (good response, Socket error #104, good response, Socket error #104...) until I restarted my application.

Share this post


Link to post
1 hour ago, dlucic said:

So, my android appllication works fine and when wifi connection broke for a second I receive Socket error #103 when I try to open one of mine TClientDataSet's. If I try it one more time it works fine again. But when I try it for the third time I receive Socket error #104. And that goes in a round (good response, Socket error #104, good response, Socket error #104...) until I restarted my application.

Why not simply catch the socket error and retry the failed operation?

Share this post


Link to post

 

That's exactly what I tried, buti it heppens exactly as I wrote. This is code on my login form. I have procedure KonektujSe where I connect to DataSnap server service and it works fine. 

 

 

image.thumb.png.14d20b7f16f0f07d2ae8326c3bcd2e9a.png

 

Than I have some code in onClick method with try except. 

 

image.thumb.png.95aa31bbf773b38e38a87b4d9156401f.png

 

When error occures I call KonektujSe procedure again but it doesn't work.

Share this post


Link to post

I have no experience with such a setup, but I would try to use "TDSProviderConnection.AfterDisconnect" event to start a timer which tries every second to call a "TDSProviderConnection.Open" until "TDSProviderConnection.connected" is true again. As long as the timer runs you block all actions which load or save data from/to the server.

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×