Skip to content

Instantly share code, notes, and snippets.

@joliver
Created December 17, 2010 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joliver/745817 to your computer and use it in GitHub Desktop.
Save joliver/745817 to your computer and use it in GitHub Desktop.
namespace ConsoleApplication1
{
using System;
using System.Transactions;
using Raven.Client.Document;
public static class MainProgram
{
private const string RavenUrl = "http://localhost:8080";
private const string CustomDatabaseName = "MyDatabase";
public static void Main()
{
try
{
Init();
}
catch (Exception)
{
}
Init2();
}
private static void Init()
{
using (var scope = new TransactionScope())
using (var store = new DocumentStore())
{
store.DefaultDatabase = CustomDatabaseName;
store.Url = RavenUrl;
store.Initialize(); // database is set to be created, but *not* actually created
using (var session = store.OpenSession())
{
// some kind of unexpected error occurs here which prevents us from
// being able to save/commit changes
throw new Exception(
"The default database name provided will now be permenantly unavailable/locked.");
session.SaveChanges();
scope.Complete(); // if we ever got here, the database would truly be created.
}
}
}
private static void Init2()
{
using (var store = new DocumentStore())
{
store.DefaultDatabase = CustomDatabaseName;
store.Url = RavenUrl;
// Raven will throw right here...
store.Initialize();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment