I'm tying to get started with the Neo4j.Driver package for .Net. I'm using Neo4j 4.0.1, and I've downloaded the latest version of the Neo4j.Driver package using NuGet.
In the Neo4j Desktop, I've created a database called "contacts", and I'm trying to write a simple .Net Core console app to query this database. In my app, I'm creating an asynchronous session for this database as follows:
_driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("neo4j", "xxxxxxxxx"));
IAsyncSession session = _driver.AsyncSession(o => o.WithDatabase("contacts"));
However, when I run my program, I get the following exception:
Neo4j.Driver.FatalDiscoveryException
HResult=0x80131500
Message=Database does not exist. Database name: 'contacts'.
Source=Neo4j.Driver
StackTrace:
at Neo4j.Driver.Internal.MessageHandling.ResponsePipelineError.EnsureThrownIf(Func`2 predicate)
at Neo4j.Driver.Internal.MessageHandling.ResponsePipelineError.EnsureThrown()
at Neo4j.Driver.Internal.Result.ResultCursorBuilder.<NextRecordAsync>d__21.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Neo4j.Driver.Internal.Result.ResultCursor.<FetchAsync>d__10.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Neo4j.Driver.ResultCursorExtensions.<ToListAsync>d__3`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Neo4jTest.Program.<Main>d__1.MoveNext() in C:\dotnet\Neo4jTest\Program.cs:line 21
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Neo4jTest.Program.<Main>d__1.MoveNext() in C:\dotnet\Neo4jTest\Program.cs:line 31
Can anyone suggest a reason why the driver is failing to find my database?
The full code of my program is as follows:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Neo4j.Driver;
namespace Neo4jTest
{
public class Program : IDisposable
{
private static IDriver _driver;
static async Task Main(string[] args)
{
List<string> people;
_driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("neo4j", "xxxxxxx"));
IAsyncSession session = _driver.AsyncSession(o => o.WithDatabase("contacts"));
try
{
IResultCursor cursor =
await session.RunAsync(
"MATCH(infectedPerson:People {infected:true}) RETURN infectedPerson.surname AS surname");
people = await cursor.ToListAsync(record => record["surname"].As<string>());
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
finally
{
await session.CloseAsync();
}
foreach (string person in people)
{
Console.WriteLine(person);
}
}
public void Dispose()
{
_driver?.Dispose();
}
}
}