How to check if driver connected to neo4j on startup?


(Matthew Browning) #1

Hello,

Was wondering if there was a way to check to see if the driver connected to the neo4j server when the driver was initialized, that way I can throw an error or panic when the application cannot connect to the server.

Thanks,
Matt


(Ali Ince) #2

Hi @MattJBrowning,

The driver behaves in a lazy way and do not actually establish any connection on construction. The actual first contact is performed when one of session.Run, session.BeginTransaction, session.ReadTransaction or session.WriteTransaction is invoked.

As a solution, you can write your own function to test connectivity using a very simple query, like RETURN 1.

I will also add a feature request regarding this functionality (something like driver.Verify() returning an error).

Thanks.