Initialization does not actually open a connection. The RavenDB client opens and closes connections as it needs to.
It will not revert to an embedded database. You have to explicitly use an EmbeddableDocumentStore
if you want an embedded database instance.
If you want to check yourself if the server is up, you can just do something and see if it fails. Probably the easiest thing you could do is to try to get the build number of the RavenDB server. This can be done using documentStore.AsyncDatabaseCommands.GetBuildNumberAsync()
.
Here are some extension methods that will help make it even easier. Put these in a static class:
public static bool TryGetServerVersion(this IDocumentStore documentStore, out BuildNumber buildNumber, int timeoutMilliseconds = 5000)
{
try
{
var task = documentStore.AsyncDatabaseCommands.GetBuildNumberAsync();
var success = task.Wait(timeoutMilliseconds);
buildNumber = task.Result;
return success;
}
catch
{
buildNumber = null;
return false;
}
}
public static bool IsServerOnline(this IDocumentStore documentStore, int timeoutMilliseconds = 5000)
{
BuildNumber buildNumber;
return documentStore.TryGetServerVersion(out buildNumber, timeoutMilliseconds);
}
Then you can use them like this:
var online = documentStore.IsServerOnline();
Or like this:
BuildNumber buildNumber;
var online = documentStore.TryGetServerVersion(out buildNumber);