public static int ShrinkDataBase(this MainForm main, CoreConfig config) { MSSqlHelper sql = new MSSqlHelper(config.ConnectionString); if (sql.Open()) { List <string> dbs = config.DataBases; if (dbs != null) { int i = 0; foreach (string db in dbs) { try { if (sql.Exist(db)) { sql.ShrinkDataBase(db); i++; } } catch (Exception) { break; } } return(i); } } return(0); }
public static int SplitDb(this ServerForm main, CoreConfig config) { MSSqlHelper sql = new MSSqlHelper(config.ConnectionString); if (sql.Open()) { List <string> dbs = config.DataBases; if (dbs != null) { int i = 0; foreach (string db in dbs) { try { if (sql.Exist(db)) { sql.SplitDataBase(db); i++; } } catch (Exception e) { main.Error(R.TipServerDbSplitFail + "\n" + e); break; } } return(i); } } return(0); }
public static int AttachDataBase(this ServerForm main, CoreConfig config) { List <string> dbs = config.DataBases; if (dbs != null) { MSSqlHelper sql = new MSSqlHelper(config.ConnectionString); if (sql.Open()) { int i = 0; foreach (string db in dbs) { string file = PathHelper.Combine(config.DatabasePath, db + ".mdf"); try { if (!sql.Exist(db)) { sql.AttachDataBase(db, file); i++; } } catch (Exception e) { main.Error(R.TipServerDbAttachFail + "\n" + file + "\n" + e.Message); break; } } return(i); } } return(0); }
public static int AttachDataBase(this MainForm main, CoreConfig config) { List <string> dbs = config.DataBases; if (dbs != null) { MSSqlHelper sql = new MSSqlHelper(config.ConnectionString); if (sql.Open()) { int i = 0; foreach (string db in dbs) { string file = PathHelper.Combine(config.DatabasePath, db + ".mdf"); try { if (sql.Exist(db)) { #if DEBUG main.Warnning("数据库已经存在:" + db); #endif } else { sql.AttachDataBase(db, file); i++; } } catch (Exception e) { #if DEBUG main.Error("分离失败\n" + e); #else main.Error("附加失败\n" + file + "\n" + e.Message); #endif break; } } return(i); } } return(0); }
public static int SplitDb(this MainForm main, CoreConfig config) { MSSqlHelper sql = new MSSqlHelper(config.ConnectionString); if (sql.Open()) { List <string> dbs = config.DataBases; if (dbs != null) { int i = 0; foreach (string db in dbs) { try { if (sql.Exist(db)) { sql.SplitDataBase(db); i++; } else { #if DEBUG main.Warnning("数据库不存在:" + db); #endif } } catch (Exception e) { #if DEBUG main.Error("分离失败\n" + e); #else main.Error("分离失败\n" + e.Message); #endif break; } } return(i); } } return(0); }
public static int CleanDataBaseLog(this MainForm main, CoreConfig config) { List <string> dbs = config.DataBases; if (dbs != null) { DirectoryInfo dir = new DirectoryInfo(config.DatabasePath); if (!dir.Exists) { return(0); } MSSqlHelper sql = new MSSqlHelper(config.ConnectionString); if (sql.Open()) { int i = 0; foreach (string db in dbs) { if (sql.Exist(db)) { #if DEBUG main.Warnning("数据库没有分离:" + db); #endif return(-1); } else { FileInfo[] files = dir.GetFiles(db + "*.ldf"); if (files != null && files.Length > 0) { files[0].Delete(); i++; } } } return(i); } } return(0); }