Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-14-2021 12:39 PM
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
Solved! Go to Solution.
12-16-2021 02:10 AM
Charlotte just beat me to it If it is the DB that you want to check exists then you have to run something against it. If it is connectivity to the server that you want to test instead then there is a Driver.VerifyConnectivityAsync() method that you can use.
12-16-2021 01:30 AM
Hi Mario,
The only way I've done this in the past is to run a simple RETURN 1
statement and use it as a test, or something like CALL dbms.components()
to get the Server version etc
Something like:
await session.RunAsync("RETURN 1");
With a try/catch
around it
Charlotte
12-16-2021 02:10 AM
Charlotte just beat me to it If it is the DB that you want to check exists then you have to run something against it. If it is connectivity to the server that you want to test instead then there is a Driver.VerifyConnectivityAsync() method that you can use.
12-22-2021 08:40 AM
Hi Charlotte and Andy,
thanks for your response.
I have test both variants and i use the Driver.VerifyConnectivityAsync().
Both spend ~3 seconds, but the dbDriver.VerifyConnectivityAsync() is calling before
create the session.
many thanks and i wich everyone a merry chistmas
Mario
All the sessions of the conference are now available online