cancel
Showing results for 
Search instead for 
Did you mean: 

detect terminated connection

Former Member
0 Kudos
2,318

Once my app starts I will try to connect and I get err if connection is not established, which is great.

var conn = sqlanywhere.createConnection();
conn.connect(connParams, function (err) ...


I keep persistent connection in my Node.js app and I struggle how to handle when connection is terminated later, when sql server is restarted or something. I get errors from conn.exec, but it would be very useful if I could check before using exec that connection has not been terminated so I can handle reconnect logic. I did not find any property or function on conn that would give me current status. Any suggestions how to detect when connection is terminated?

Thank you.

Vlad
Product and Topic Expert
Product and Topic Expert
0 Kudos

There is a similar question, but for a different API and different server: http://sqlanywhere-forum.sap.com/questions/23217/sybaseiq-c-check-if-connected Maybe this is what you need!

Accepted Solutions (0)

Answers (1)

Answers (1)

jack_schueler
Advisor
Advisor

Unlike ADO.NET, there are no properties associated with the connection (i.e., there is no conn.State to test).

In this case, a liveness test can be implemented by executing a "SELECT 1" which will always succeed if a connection is present and fail when it isn't. But then you didn't want to use exec.