-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Labels
Description
The following code errors with
nhandled exception. Neo4j.Driver.ServiceUnavailableException: Unable to connect to database, ensure the database is running and that there is a working network connection to it.
---> Neo4j.Driver.ServiceUnavailableException: Failed to find server info for 'neo4j://localhost:7687/' for database 'system'.
using Neo4j.Driver;
string dbUri = "localhost";
string dbUser = "neo4j";
string dbPassword = "verysecret";
var addresses = ServerAddress.From(dbUri, 7687);
using var driver = GraphDatabase.Driver(
"neo4j://example.com:9999",
AuthTokens.Basic(dbUser, dbPassword),
conf => conf.WithResolver(new ListAddressResolver(addresses))
);
await driver.VerifyConnectivityAsync();
class ListAddressResolver : IServerAddressResolver {
private readonly ServerAddress[] _servers;
public ListAddressResolver(params ServerAddress[] servers) {
_servers = servers;
}
public ISet<ServerAddress> Resolve(ServerAddress address) {
return new HashSet<ServerAddress>(_servers);
}
}
The issue is two-fold:
- the driver claims the server is not available at
localhost:7687
, while there is one up and running. Grant's assessment is that the port is ignored. This is thus a bug because the error message claims to be connecting to port 7687 while (apparently?) it's actually reaching to 9999. - it would make for a hugely improved UX if we provided a default implementation of
ListAddressResolver
so users don't have to copy-paste the boilerplate. In the end there's rarely anything special happening there: most often it's just a list of addresses.