Neo4j.Driver.FatalDiscoveryException Database does not exist

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();
        }
    }
}

Hey @ptipper,

Could you open your DB in the browser, run:

:use system  

Then

show databases

Do you see the contacts database there?

Chris

Hi Chris,

Thanks for the reply. I typed in the commands you gave above, and it lists the neo4j and system databases, and there's no mention of a contacts database, so I guess this is the immediate cause of the error.

As I said, I'm pretty new to Neo4j, so maybe I'm getting confused as to what's actually meant by a "database" here. When I created my database, I first of all created a project in the Neo4j desktop called "contact-tracer", and then clicked the Add Graph button to create "contacts". So what kind of entity is "contacts", then; is it a database (it certainly looks like one!), or is it something else? And how do I connect to it using the Neo4j.Driver library in .Net?

Hey Paul,

So - the 'contacts-tracer' you have is a 'Project', and the 'contacts' is a 'Database Server Instance'. In pre 4.0 days, you could only have 1 DB per instance, so 'Database' made more sense then.

In essence your 'contacts' is a friendly name for you to see what that database is setup as. For example, you might name it 'contacts_v1' and have a 'contacts_v2' server as well (or vX....)

Inside that instance, you have two databases, system and neo4j - System contains all the security etc, and neo4j is the default instance. If you wanted to have a contacts db in there as well, you would first go to the System db:

:use system

Then run:

CREATE DATABASE contacts

Then, in the browser - you would switch to that DB by running :use contacts

However, for simplicity sake - if I were you - I would just use the default database, and would change
the:

IAsyncSession session = _driver.AsyncSession(o => o.WithDatabase("contacts"));

to:

IAsyncSession session = _driver.AsyncSession();

As unless you need multiple databases at the moment, I wouldn't worry.

On the plus side - if you do need it later - you're already ahead of the curve :slight_smile:

All the best

Chris

Chris,

I removed the lambda expression from the _driver.AsyncSession() call as you suggested, and it worked a charm! :smiley:

Thanks very much for clarifying this. :+1:

No worries - if you have any troubles - feel free to reach out - I'm pretty easy to find :)