My application may go for hours between queries and so the Server often times out and closes the connection. As far as I can see, the only way to deal with this is to add
Code: Select all
if not(Myconnection.Connected) then
Myconnection.Connect;
to every query's BeforeOpen, BeforeExecute, BeforePost, etc.... event. This seems very inefficient and poor coding to me! I have seem comments about using the OnConnectionLost event but I feel that is almost as bad, it seems it does not work in all circumstances and is really just a way to keep a connection open, even when it's not needed. In fact I have added the example code to my app and it does not seem to help. I feel I just need a centralized way to check for and re-open a connection before any attempt is made to access the DB. Is there some recommended way to do this - or I am completely missing something?
As a secondary question, I have been using both MyQuery.Open and MyQuery.Execute in my code. Both work fine but I see that MyQuery.Execute is basically a MyQuery.Prepare followed by MyQuery.Open. Would I be better off changing all MyQuery.Open to MyQuery.Execute (or the other way round)?
David.