Could someone please tell me how can i check if there is an active connection to sybaseIQ? I would like to perform a check before sending statements so that I have a chance to re-establish the connection in case it was lost. I am using sacapi.h, sacapidll.cpp, sacapidll.h (SQL Anywhere C API which is layered on top of the DBLIB package and it was implemented with Embedded SQL). I don't think callbacks are supported. I can't find documentation on sqlany_register_callback in the SybaseIQ documentation |
Hm, according to the v16 online docs, I stand corrected w.r.t. my statement the C API would not support a callback (I had just checked for v12.0.1, see my comment on the question):
Note: That's what the docs say, I have not tested that myself... And here's the whole story including a sample from the according CR note 738036 as released with v16.0.0.1522 and above, and these versions do contain an according sample "callback.cpp", too. unfortunately it's not supported in SybaseIQ :(
(30 Dec '14, 06:50)
lefteris
|
It is not a Sybase IQ forum, however why could not you simply try to execute the statement. If it fails, then check the exception details, reconnect and then execute it again.
I am also not sure, but SybaseIQ probably provides a way to connect your callback handler with something. And if the connection is lost, the appropriate callback should be triggered.
What API / utility are you using?
I can't find a SybaseIQ forum, and it seems the sybaseIQ connector for c++ is the same as the sqlanywhere connector. The header file of my connector defines a callback a function that returns an int and has no parameters, but there is no documentation on how it is used.
As for your suggestion of trial and error this is my current approach. I was just looking for something better.
I found only this article, but I do not know if you can use Embedded SQL in the code. http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01776.1604/doc/html/san1357754953945.html
The function what you found is desribed here: http://dcx.sybase.com/index.html#sa160/en/dbprogramming/programming-sacpp-sacapi-h-fil-sqlany-register-callback-met.html
Unfortunately, I do not know if this info can help you for Sybase IQ.
Ah, the C API - then it seems there's no official callback handling to get notified of dropped connections, as is possible in ESQL with db_register_a_callback (and type DB_CALLBACK_CONN_DROPPED). Via ODBC, you could use the SQL_ATTR_CONNECTION_DEAD connection attribute.
As the C API is based on ESQL and functions like sqlany_make_connection() are said to use a SQLCA, it might somehow be possible to access that to register a callback but that's very wild guessing on my part.
As Vlad, I would suggest to try to execute the statements and handle a disconnect error accordingly...
By the way, I thought a little bit, and I still agree with myself, that the exception checking, and repeating the connection is the best solution. There could be scenarios, when the connection is lost, none of packets are sent to the server (we assume that there is not keep-alive load), and in this case, the application will not be able to understand whether it was disconnected or not. Only when you send any request (it is better to send your particular SQL query), it will fail, and only this is the reliable way to determine that something was wrong.
You can use this approach for anything you want. Even to read packets through the power cable plugged to someone's washing machine :)