public static void CreateEmpty(string catalog) { var datasource = new SqlConnectionStringBuilder(Config.Settings.ConnectionString).DataSource; Log.i("DB", $"Creating database \'{catalog}\' in \'{datasource}\'."); MasterDatabase.Execute($"CREATE DATABASE {catalog}"); }
static void Drop(string catalog) { Log.i("DB", "Dropping database '" + catalog + "'."); MasterDatabase.Execute($@"WHILE EXISTS(select NULL from sys.databases where name='{catalog}') BEGIN DECLARE @SQL varchar(max) SELECT @SQL = COALESCE(@SQL,'') + 'Kill ' + Convert(varchar, SPId) + ';' FROM MASTER..SysProcesses WHERE DBId = DB_ID(N'{catalog}') AND SPId <> @@SPId EXEC(@SQL) DROP DATABASE [{catalog}] END"); }