public static bool DatabaseExists(this DbProviderFactory dbProviderFactory, string connectionString, string providerName, ISqlDialect dialect) { var connectionStringManipulator = new ConnectionStringManipulator(dbProviderFactory, connectionString); using (var connection = dbProviderFactory.CreateConnection()) { connection.ConnectionString = connectionStringManipulator.GetRootConnectionString(); connection.Open(); var databaseName = connectionStringManipulator.GetDatabaseName(); return(connection.Query(dialect.CheckDatabaseExists(databaseName)).Any()); } }
private static void CreateDatabaseIfNotExists(ConnectionStringSettings connectionStringSettings, DbProviderFactory factory, ISqlDialect dialect) { using (new TimedOperation("-- Checking for Existence of Database...")) { var connectionStringManipulator = new ConnectionStringManipulator(connectionStringSettings.ToSystem()); using (var connection = factory.CreateConnection()) { connection.ConnectionString = connectionStringManipulator.GetRootConnectionString().ConnectionString; connection.Open(); var databaseName = connectionStringManipulator.GetDatabaseName(); Trace("Looking for {0}", databaseName); if (!connection.Query(dialect.CheckDatabaseExists(databaseName)).Any()) { Trace("Not Found"); Trace("Creating"); connection.Execute(dialect.CreateDatabase(databaseName)); Trace("Created"); } else { Trace("Found!"); } } } }
private static void CreateDatabaseIfNotExists(ConnectionStringSettings connectionStringSettings, DbProviderFactory factory, ISqlDialect dialect) { using (new TimedOperation("-- Checking for Existence of Database...")) { var connectionStringManipulator = new ConnectionStringManipulator(connectionStringSettings.ToSystem()); using (var connection = factory.CreateConnection()) { connection.ConnectionString = connectionStringManipulator.GetRootConnectionString().ConnectionString; connection.Open(); var databaseName = connectionStringManipulator.GetDatabaseName(); Trace("Looking for {0}", databaseName); if (!connection.Query(dialect.CheckDatabaseExists(databaseName)).Any()) { Trace("Not Found"); Trace("Creating"); connection.Execute(dialect.CreateDatabase(databaseName)); Trace("Created"); } else { Trace("Found!"); } } } }