Search code examples
asp.netravendbnancy

When calling RavenDb store.DatabaseCommands.GlobalAdmin.CreateDatabase() the call hangs


The project that I am currently working on is using RavenDb as an embedded datastore, while attempting to call out to make sure that the database exists in the store, I am finding that it hangs.

        var docStore = new EmbeddableDocumentStore()
            {
                DataDirectory = "Data",
            };

        docStore.Initialize();

        // Check to make sure that the database exists
        bool bcDatabaseExists = docStore.DatabaseCommands.GlobalAdmin.GetDatabaseNames(1024).Contains(DatabaseName);
        if (!bcDatabaseExists)
        {
            Dictionary<string, string> settings = new Dictionary<string, string>();

            DatabaseDocument databaseDocument = new DatabaseDocument()
            {
                Id = DatabaseName,
                Settings = 
                {
                    { "Raven/DataDir", "~\\Data" }
                }
            };

            try
            {
                docStore.DatabaseCommands.GlobalAdmin.CreateDatabase(databaseDocument);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }

However when I hit the CreateDatabase call the process just hangs without any notification. I wanted to check to make sure I wasn't using the call incorrectly, or if there was a better call.

Any thoughts or suggestions that you can offer would be greatly appreciated.


Solution

  • Although the question has nothing to do with NancyFX, probably you need EnsureDatabaseExists method. It will create the database, if it's not there yet.