public virtual void EnsureDatabaseExists(string database) { if (string.IsNullOrEmpty(database)) { return; } var dbCreated = false; var shouldCheckCouch = false; ServerCommand command = null; try { shouldCheckCouch = !_databaseExists.TryGetValue(database, out dbCreated); if (shouldCheckCouch && !dbCreated) { command = commandFactory.CreateServerCommand(); command.CreateDatabase(database); _databaseExists[database] = true; } } catch (WebException webEx) { if (webEx.Message.Contains("(412) Precondition Failed")) { _databaseExists[database] = true; } else { "An exception occurred while trying to check for the existence of database {0} at uri {1}. \r\n\t {2}" .ToError <IDocumentRepository>(database, command.Uri, webEx); throw; } } catch (Exception ex) { "An exception occurred while trying to check for the existence of database {0} at uri {1}. \r\n\t {2}" .ToError <IDocumentRepository>(database, command.Uri, ex); throw; } }