Home > Back-end >  Raven.Client.Exceptions.Database.DatabaseDoesNotExistException: 'Database '*****' doe
Raven.Client.Exceptions.Database.DatabaseDoesNotExistException: 'Database '*****' doe

Time:04-05

I am using RavenTestDriver for my .net core unit tests . Here is my configuration of my RavenTestDriver in my unit test solution :

public class TestHostBuilder : RavenTestDriver, IAsyncLifetime
    {


        public async Task InitializeAsync()
        {

            ConfigureServer(new TestServerOptions
            {

                CommandLineArgs = new System.Collections.Generic.List<string> { "--RunInMemory=true", },
                FrameworkVersion = null,
            });

            var hostBuilder = easy.api.Program.CreateHostBuilder(new string[0])
         .ConfigureWebHost(webHostBuilder =>
         {
             webHostBuilder.UseTestServer();
         })
        .ConfigureServices(services =>
        {
               services.AddScoped<ICurrentUserService, InitRequest>();
                services.AddRavenDbAsyncSession(GetDocumentStore());
                services.AddScoped<IAsyncDocumentSession>((c) =>
            {
                return GetDocumentStore().OpenAsyncSession(new SessionOptions()
                {
                    Database="test-server"
                });
                });
        });

            var host = hostBuilder.Start();
        }

    }

But when I call my Repository to get the object I get this error :

Database 'test-server' does not exist.'
   at Raven.Client.Exceptions.Database.DatabaseDoesNotExistException.Throw(String databaseName) in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Exceptions\Database\DatabaseDoesNotExistException.cs:line 35
   at Raven.Client.Http.RequestExecutor.<ExecuteAsync>d__114`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Http\RequestExecutor.cs:line 883
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Raven.Client.Http.RequestExecutor.<ExecuteAsync>d__114`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Http\RequestExecutor.cs:line 900
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Raven.Client.Http.RequestExecutor.<UpdateTopologyAsync>d__101.MoveNext() in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Http\RequestExecutor.cs:line 455
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Raven.Client.Http.RequestExecutor.<FirstTopologyUpdate>d__109.MoveNext() in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Http\RequestExecutor.cs:line 678
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Raven.Client.Http.RequestExecutor.<WaitForTopologyUpdate>d__107.MoveNext() in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Http\RequestExecutor.cs:line 613
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Raven.Client.Http.RequestExecutor.<UnlikelyExecuteAsync>d__106`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Http\RequestExecutor.cs:line 583
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Raven.Client.Documents.Session.AsyncDocumentSession.<LoadAsync>d__51`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3\53009\src\Raven.Client\Documents\Session\AsyncDocumentSession.Load.cs:line 30
   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 infrastructure.Persistence.RavenDb.RavenRepository`1.<GetByIdAsync>d__6.MoveNext() in D:\gitProjects\Orbis\infrastructure\Persistence\RavenDb\RavenRepository.cs:line 83
   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 infrastructure.ApplicationCache.CacheableRepository`1.<GetAsync>d__8.MoveNext() in D:\gitProjects\Orbis\infrastructure\ApplicationCache\CacheableRepository.cs:line 48
   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 easy.api.Application.Setting.Queries.GetClientAppSettingQueryHandler.<Handle>d__4.MoveNext() in D:\gitProjects\**\***\Application\Setting\Queries\GetClientAppSettingQuery.cs:line 35
   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 api.common.Behaviors.UnhandledExceptionBehaviour`2.<Handle>d__2.MoveNext() in D:\gitProjects\**\api.common\Behaviors\UnhandledExceptionBehaviour.cs:line 22

CodePudding user response:

You need to create the database before calling OpenAsyncSession https://ravendb.net/docs/article-page/5.3/csharp/client-api/operations/server-wide/create-database#example

  • Related