diff --git a/model/DBHelper.cs b/model/DBHelper.cs index 52eb0359..e63eae9f 100644 --- a/model/DBHelper.cs +++ b/model/DBHelper.cs @@ -39,13 +39,16 @@ public static void ExecBatchSql(string conn, string sql) { public static void DropDb(string conn) { var cnBuilder = new SqlConnectionStringBuilder(conn); - var dbName = cnBuilder.InitialCatalog; - if (DbExists(cnBuilder.ToString())) { + var initialCatalog = cnBuilder.InitialCatalog; + + var dbName = "[" + initialCatalog + "]"; + + if (DbExists(cnBuilder.ToString())) { cnBuilder.InitialCatalog = "master"; ExecSql(cnBuilder.ToString(), "ALTER DATABASE " + dbName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE"); ExecSql(cnBuilder.ToString(), "drop database " + dbName); - cnBuilder.InitialCatalog = dbName; + cnBuilder.InitialCatalog = initialCatalog; ClearPool(cnBuilder.ToString()); } } @@ -54,7 +57,7 @@ public static void CreateDb(string conn) { var cnBuilder = new SqlConnectionStringBuilder(conn); var dbName = cnBuilder.InitialCatalog; cnBuilder.InitialCatalog = "master"; - ExecSql(cnBuilder.ToString(), "CREATE DATABASE " + dbName); + ExecSql(cnBuilder.ToString(), "CREATE DATABASE [" + dbName + "]"); } public static bool DbExists(string conn) {