Connection Handle From VFP to SQL


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,

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

To test this situation you may use TRY ... CATCH:

llSuccess = .F.

  lnResult = SQLEXEC(lnHandle, "SELECT * FROM YourTestTable", "cTable")
  IF lnResult < 0
    *-- Process SQL error
    llSuccess = .T.
CATCH TO loException
  *-- Process Invalid handle exception here

IF !llSuccess
  *-- ...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZirckAuthor Commented:

Works perfect. I can manage both case with this!!

Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.