public static void DropExistingDb(string connectionString, string dbName) { try { Server server = MDSModelling.ConnectToServer(connectionString); if (server != null) { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString); if (string.IsNullOrWhiteSpace(dbName)) { throw new Exception("dbName (initial catalog) is empty"); } else { Database database = server.Databases[dbName]; if (database == null) { throw new Exception(string.Format("database with name {0} not found", dbName)); } database.Drop(); } } else { throw new Exception(string.Format("cannot connect to SQL server with connection string : {0}", connectionString)); } } catch (Exception ex) { throw ex; } }
public static void DropExistingDb(string dataSource, string initialCatalog, string DataBase) { try { Database database = MDSModelling.ConnectToServer(dataSource, initialCatalog).Databases[DataBase]; if (database == null) { return; } database.Drop(); } catch (Exception ex) { throw ex; } }