Showing results for 
Search instead for 
Did you mean: 

verify connection to database


I've ben testing whether my databse query handler can detect whether the datase conneciton is still active, and if not, log queries to file until the databse connection becomes active again. Our methods until now have been like those described here:

db conn.png

Basically, we store the connection reference in a shif register, and check a property of the connection. If this returns an error, your connection is bad and you try to connect again. I've tested this by putting my Open Connection VI in a loop and then disconnecting the ethernet cable or VPN required to connect to our database, and the response from the property node continues to return a value without error. This is odd.


So, I replaced this check with a query (Select USER() is pretty fast), and the failed query robustly detects the lost connection. But it does thake more time. Any reason why method one doesn't work?


db conn_2.png


0 Kudos
Message 1 of 3

Probably because some of the properties are maintained in the local reference rather than being fetched from the server. You might be able to use the properties to detect if you have 'created' or 'opened' a connection (versus an 'invalid reference'), but it might not actually 'connect' to the server until you come to do a query. Some libraries for things like this have connected/disconnected properties or events - but I think the best way to check you have a valid connection is to do a simple query (as that verifies two-way connection, user credentials, responsiveness of DB etc.).


For example, if you had an instrument driver and requested the 'DriverVersion' property, I wouldn't expect that to require access to the hardware.

0 Kudos
Message 2 of 3

Thank you for the helpful response. I'm happy with the solution of using a query to verify the connection.

0 Kudos
Message 3 of 3