Exemplo n.º 1
0
        public static void CreateDatabaseIfNotExists(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();
                if (!connection.Query(dialect.CheckDatabaseExists(databaseName))
                    .Any())
                {
                    connection.Execute(dialect.CreateDatabase(databaseName));
                }
            }
        }
Exemplo n.º 2
0
 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!");
             }
         }
     }
 }
Exemplo n.º 3
0
 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!");
             }
         }
     }
 }