Problem : Connection Handle From VFP to SQL
Hi,
I’m developing a client-side application on FoxPro with a back-end on SQL Express 2005. After many search and try, I have not find the perfect solution to my problem.
When my application start, I try to establish the connection with the SQL server based on a .ini file. No problem with this. If the connection is not made, I display a warning but It let the application start anyway because the problem could be not on the client side but can be on the server side.
My problem:
I would like to have a bullet proof Procedure, to test maybe with a timer (10 mins) , the connection state of the SQL connection between the Client Application and the server.
Even if the Handle is not valid!
Because, I see two possibility with the Handle.
First, the handle was correctly initialized and the connection was lost after the application was started. In this case, I use a SQLEXEC to grab some test data just to check if the result of the query is higher that 0.
Second, the handle was not initialize at the startup due to a connection problem. In this case, the handle is not valid…
How can I manage to deal with invalid handle…
In other word, I don’t want to make a SQLConnect() to see the result each time that I want to check the connection state…. And If I use a SQLEXEC() with an invalid handle, I got error…
Thanks in advance,
Solution : Connection Handle From VFP to SQL
To test this situation you may use TRY … CATCH:
llSuccess = .F.
TRY
lnResult = SQLEXEC(lnHandle, “SELECT * FROM YourTestTable”, “cTable”)
IF lnResult < 0
*– Process SQL error
ELSE
llSuccess = .T.
ENDIF
CATCH TO loException
*– Process Invalid handle exception here
ENDTRY
IF !llSuccess
*– …
ENDIF