Created
December 17, 2010 22:22
-
-
Save joliver/745817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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