Hello,
i am beginner on neo4j, but not on .net and c#.
On other databases i can open the connector and if database is offline throw the connector an exeption or i can test it with a attach-function.
How can i do it on neo4j?
My "testcode":
// test connect to Neo4j
using (IDriver dbDriver = GraphDatabase.Driver("neo4J://localhost:7687", AuthTokens.Basic("neo4j", "none")))
{
// it is possible here to check is server reachable?
using (IAsyncSession dbSession = dbDriver.AsyncSession(o => o.WithDatabase("mydatabase")))
{
// or check it on this position?
string query = @"MATCH (n) RETURN n";
try
{
var result = await dbSession.ReadTransactionAsync(async tx =>
{
var cursor = await tx.RunAsync(query);
var fetched = await cursor.FetchAsync();
var output = new List<object>();
while (fetched)
{
output.Add(cursor.Current["n"]);
fetched = await cursor.FetchAsync();
}
return output;
});
await dbSession.CloseAsync();
}
catch (Exception ex)
{
// only the ReadTransactionAsync throws exception
}
}
await dbDriver.CloseAsync();
}
regards Mario