// Token: 0x0600027F RID: 639 RVA: 0x00009424 File Offset: 0x00007624 public static void ShrinkAccess() { DbConfigInfo dbConfig = DbConfigs.GetDbConfig(); string mapPath = FPUtils.GetMapPath(WebConfig.WebPath + dbConfig.dbpath); string mapPath2 = FPUtils.GetMapPath(WebConfig.WebPath + "cache/temp/"); if (!File.Exists(mapPath)) { throw new Exception("目标数据库不存在,无法压缩"); } if (!Directory.Exists(mapPath2)) { Directory.CreateDirectory(mapPath2); } if (File.Exists(mapPath2 + Path.GetFileName(mapPath))) { File.Delete(mapPath2 + Path.GetFileName(mapPath)); } string destconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mapPath2 + Path.GetFileName(mapPath); JetEngineClass jetEngineClass = new JetEngineClass(); jetEngineClass.CompactDatabase(dbConfig.connectionstring, destconnection); File.Copy(mapPath2 + Path.GetFileName(mapPath), mapPath, true); File.Delete(mapPath2 + Path.GetFileName(mapPath)); }
public override void Load() { var dbConfigs = new DbConfigs() { Encrypt = defaultValue.GetValue <bool>("DbConfigs:Encrypt"), Type = defaultValue.GetValue <string>("DbConfigs:Type"), ConnectionString = defaultValue.GetValue <string>("DbConfigs:ConnectionString") }; using (var db = new CompanyDbContext(dbConfigs)) { db.Database.EnsureCreated(); //检查默认配置 var enumerable = defaultValue.AsEnumerable(); foreach (var value in enumerable) { if (value.Value != null) { var config = db.Config.FirstOrDefault(a => a.Name == value.Key); if (config == null) { config = new Config { Name = value.Key, Value = value.Value }; db.Config.Add(config); } db.SaveChanges(); } } Data = db.Config.ToDictionary(c => c.Name, c => c.Value); } }
private void FormMain_Shown(object sender, EventArgs e) { if (!DbConfigs.IsOnLine()) { MessageBox.Show("没有联网", "system message", MessageBoxButtons.AbortRetryIgnore); return; } }
// Token: 0x06000009 RID: 9 RVA: 0x000028D0 File Offset: 0x00000AD0 protected override void View() { this.dbconfig = DbConfigs.GetDbConfig(); this.dbsize = FPUtils.FormatBytesStr(DbBll.GetDbSize()); if (this.ispost) { DbBll.ShrinkDatabase(); } base.SaveRightURL(); }
// Token: 0x0600027E RID: 638 RVA: 0x000091C8 File Offset: 0x000073C8 public static void ShrinkSqlServer() { DbConfigInfo dbConfig = DbConfigs.GetDbConfig(); string text = ""; string dbname = dbConfig.dbname; text += "SET NOCOUNT ON "; text += "DECLARE @LogicalFileName sysname, @MaxMinutes INT, @NewSize INT "; text = text + "USE [" + dbname + "] -- 要操作的数据库名 "; text = text + "SELECT @LogicalFileName = '" + dbname + "_log', -- 日志文件名 "; text += "@MaxMinutes = 10, -- Limit on time allowed to wrap log. "; text += "@NewSize = 1 -- 你想设定的日志文件的大小(M) "; text += "-- Setup / initialize "; text += "DECLARE @OriginalSize int "; text += "SELECT @OriginalSize = 0"; text += "FROM sysfiles "; text += "WHERE name = @LogicalFileName "; text += "SELECT 'Original Size of ' + db_name() + ' LOG is ' + "; text += "CONVERT(VARCHAR(30),@OriginalSize) + ' 8K pages or ' + "; text += "CONVERT(VARCHAR(30),(@OriginalSize*8/1024)) + 'MB' "; text += "FROM sysfiles "; text += "WHERE name = @LogicalFileName "; text += "CREATE TABLE DummyTrans "; text += "(DummyColumn char (8000) not null) "; text += "DECLARE @Counter INT, "; text += "@StartTime DATETIME, "; text += "@TruncLog VARCHAR(255) "; text += "SELECT @StartTime = GETDATE(), "; text += "@TruncLog = 'BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY' "; text += "DBCC SHRINKFILE (@LogicalFileName, @NewSize) "; text += "EXEC (@TruncLog) "; text += "-- Wrap the log if necessary. "; text += "WHILE @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired "; text += "AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName) "; text += "AND (@OriginalSize * 8 /1024) > @NewSize "; text += "BEGIN -- Outer loop. "; text += "SELECT @Counter = 0 "; text += "WHILE ((@Counter < @OriginalSize / 16) AND (@Counter < 50000)) "; text += "BEGIN -- update "; text += "INSERT DummyTrans VALUES ('Fill Log') "; text += "DELETE DummyTrans "; text += "SELECT @Counter = @Counter + 1 "; text += "END "; text += "EXEC (@TruncLog) "; text += "END "; text += "SELECT 'Final Size of ' + db_name() + ' LOG is ' + "; text += "CONVERT(VARCHAR(30),size) + ' 8K pages or ' + "; text += "CONVERT(VARCHAR(30),(size*8/1024)) + 'MB' "; text += "FROM sysfiles "; text += "WHERE name = @LogicalFileName "; text += "DROP TABLE DummyTrans "; text += "SET NOCOUNT OFF "; DbHelper.ExecuteSql(text); }
// Token: 0x0600027D RID: 637 RVA: 0x00009190 File Offset: 0x00007390 public static void ShrinkDatabase() { DbConfigInfo dbConfig = DbConfigs.GetDbConfig(); if (dbConfig.dbtype == FangPage.Data.DbType.SqlServer) { DbBll.ShrinkSqlServer(); } else { DbBll.ShrinkAccess(); } }
// Token: 0x0600004E RID: 78 RVA: 0x00006AA4 File Offset: 0x00004CA4 protected override void View() { long sysSize = SysBll.GetSysSize(); this.websize = FPUtils.FormatBytesStr(sysSize); this.dbconfig = DbConfigs.GetDbConfig(); this.dbsize = FPUtils.FormatBytesStr(DbBll.GetDbSize()); if (this.role.desktop == "") { this.role.desktop = "0"; } SqlParam sqlParam = DbHelper.MakeAndWhere(string.Format("([hidden]=0 AND [uid]={0}) OR ([hidden]=0 AND [system]=1 AND [id] IN({1}))", this.userid, this.role.desktop), WhereType.Custom, ""); this.desktoplist = DbHelper.ExecuteList <DesktopInfo>(OrderBy.ASC, new SqlParam[] { sqlParam }); base.SaveRightURL(this.pagename); }
// Token: 0x06000280 RID: 640 RVA: 0x0000950C File Offset: 0x0000770C public static long GetDbSize() { DbConfigInfo dbConfig = DbConfigs.GetDbConfig(); long num = 0L; if (dbConfig.dbtype == FangPage.Data.DbType.SqlServer) { string commandText = "SELECT OBJECT_NAME(ID) AS TableName,SIZE = sum(reserved) * CONVERT(FLOAT, (SELECT LOW FROM MASTER.DBO.SPT_VALUES WHERE NUMBER = 1 AND TYPE = 'E')) FROM [sysindexes] WHERE [indid] IN (0,1,255) GROUP BY ID ORDER BY SIZE DESC"; DataTable dataTable = DbHelper.ExecuteDataset(CommandType.Text, commandText).Tables[0]; foreach (object obj in dataTable.Rows) { DataRow dataRow = (DataRow)obj; num += long.Parse(dataRow["size"].ToString()); } } else { FileInfo fileInfo = new FileInfo(FPUtils.GetMapPath(WebConfig.WebPath + dbConfig.dbpath)); num = fileInfo.Length; } return(num); }
/// <summary> /// 关系映射 /// </summary> /// <param name="type">实体类Type</param> public TableMap(Type type) { ModelList = new Dictionary <PropertyInfo, FieldMapState>(); object[] attrs; //变量属性 FieldMapState fieldMapState; #region 类属性 //类属性 ClassInfo = new DBAttribute(); attrs = type.GetCustomAttributes(typeof(DBAttribute), false); ClassInfo = attrs.Length == 0 ? new DBAttribute() : ((DBAttribute)attrs[0]); if (ClassInfo.Name.IsNullOrEmpty()) { ClassInfo.Name = type.Name; } #region 自动创建数据库配置文件 if (DbConfigs.ConfigInfo.DbList.Count == 0 && ClassInfo.DbIndex == 0) { var db = new DbConfig(); db.DbList.Add(new DbInfo { Catalog = "数据库名称", CommandTimeout = 60, ConnectTimeout = 30, DataType = DataBaseType.SqlServer, DataVer = "2005", PassWord = "******", PoolMaxSize = 100, PoolMinSize = 16, Server = ".", UserID = "sa" }); DbConfigs.SaveConfig(db); } else if (DbConfigs.ConfigInfo.DbList.Count - 1 < ClassInfo.DbIndex) { throw new Exception("数据库配置(索引项:" + ClassInfo.DbIndex + ")不存在!"); } #endregion #region 获取DbConfig的配置 DbInfo dbInfo = ClassInfo.DbIndex; ClassInfo.ConnStr = DbFactory.CreateConnString(ClassInfo.DbIndex); ClassInfo.DataType = dbInfo.DataType; ClassInfo.DataVer = dbInfo.DataVer; ClassInfo.CommandTimeout = dbInfo.CommandTimeout; #endregion #endregion #region 变量属性 //遍历所有属性变量,取得对应使用标记名称 //无加标记时,则为不使用该变量。 foreach (var propertyInfo in type.GetProperties()) { fieldMapState = new FieldMapState(); // 是否带属性 attrs = propertyInfo.GetCustomAttributes(false); foreach (var item in attrs) { // 加入属性 fieldMapState.IsDbField = !(item is NotJoinAttribute); // 数据类型 if (item is DataTypeAttribute) { fieldMapState.DataType = (DataTypeAttribute)item; continue; } // 字段映射 if (item is ColumnAttribute) { fieldMapState.Column = (ColumnAttribute)item; continue; } // 属性扩展 if (item is PropertyExtendAttribute) { fieldMapState.PropertyExtend = ((PropertyExtendAttribute)item).PropertyExtend; continue; } } //if (fieldMapState.Display == null) { fieldMapState.Display = new DisplayAttribute { Name = propertyInfo.Name }; } //if (fieldMapState.Display.Name.IsNullOrEmpty()) { fieldMapState.Display.Name = propertyInfo.Name; } if (fieldMapState.Column == null) { fieldMapState.Column = new ColumnAttribute { Name = propertyInfo.Name }; } if (fieldMapState.Column.Name.IsNullOrEmpty()) { fieldMapState.Column.Name = propertyInfo.Name; } if (fieldMapState.IsDbField && fieldMapState.Column.IsDbGenerated) { IndexName = fieldMapState.Column.Name; } else { fieldMapState.Column.IsDbGenerated = false; } //添加属变量标记名称 ModelList.Add(propertyInfo, fieldMapState); } #endregion Type = type; }
private static void GetProvider() { try { _instance = (IDataProvider)Activator.CreateInstance(Type.GetType(string.Format("LiteCMS.Data.{0}.DataProvider, LiteCMS.Data.{0}", DbConfigs.GetConfig().Dbtype), false, true)); } catch { throw new Exception("请检查Dbtype节点数据库类型是否正确,例如:SqlServer、Access、MySql"); } }
public CompanyDbContext(IOptions <DbConfigs> config) { dbConfig = config.Value; }
public CompanyDbContext(DbConfigs config) { dbConfig = config; }
// Token: 0x0600027C RID: 636 RVA: 0x00008E34 File Offset: 0x00007034 public static string RestoreDatabase(string backupfile) { string result; if (!File.Exists(backupfile)) { result = "备份文件已不存在。"; } else { DbConfigInfo dbConfig = DbConfigs.GetDbConfig(); if (dbConfig.dbtype == FangPage.Data.DbType.SqlServer) { SQLServer sqlserver = new SQLServerClass(); if (Path.GetExtension(backupfile) == ".zip" || Path.GetExtension(backupfile) == ".config") { FPZip.UnZipFile(backupfile, ""); } backupfile = string.Concat(new string[] { Path.GetDirectoryName(backupfile), "\\", Path.GetFileName(backupfile), "\\", dbConfig.dbname, ".bak" }); if (!File.Exists(backupfile)) { return("备份文件已不存在。"); } try { sqlserver.Connect(dbConfig.dbpath, dbConfig.userid, dbConfig.password); QueryResults queryResults = sqlserver.EnumProcesses(-1); int num = -1; int num2 = -1; for (int i = 1; i <= queryResults.Columns; i++) { string text = queryResults.get_ColumnName(i); if (text.ToUpper().Trim() == "SPID") { num = i; } else if (text.ToUpper().Trim() == "DBNAME") { num2 = i; } if (num != -1 && num2 != -1) { break; } } for (int i = 1; i <= queryResults.Rows; i++) { int columnLong = queryResults.GetColumnLong(i, num); string columnString = queryResults.GetColumnString(i, num2); if (columnString.ToUpper() == dbConfig.dbname.ToUpper()) { sqlserver.KillProcess(columnLong); } } ((_Restore) new RestoreClass { Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database, Files = backupfile, Database = dbConfig.dbname, ReplaceDatabase = true }).SQLRestore(sqlserver); File.Delete(backupfile); return(string.Empty); } catch (Exception ex) { return(ex.Message); } finally { sqlserver.DisConnect(); } } string mapPath = FPUtils.GetMapPath(WebConfig.WebPath + Path.GetDirectoryName(dbConfig.dbpath)); try { if (!Directory.Exists(mapPath)) { Directory.CreateDirectory(mapPath); } if (Path.GetExtension(backupfile) == ".zip" || Path.GetExtension(backupfile) == ".config") { FPZip.UnZipFile(backupfile, mapPath); } else { File.Copy(backupfile, mapPath + "\\" + dbConfig.dbname); } result = string.Empty; } catch (Exception ex) { result = ex.Message; } } return(result); }
// Token: 0x0600027B RID: 635 RVA: 0x00008AA4 File Offset: 0x00006CA4 public static string BackUpDatabase() { string mapPath = FPUtils.GetMapPath(WebConfig.WebPath + "backup/datas"); if (!Directory.Exists(mapPath)) { Directory.CreateDirectory(mapPath); } DbConfigInfo dbConfig = DbConfigs.GetDbConfig(); string str = dbConfig.dbname + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); if (dbConfig.dbtype == FangPage.Data.DbType.SqlServer) { SQLServer sqlserver = new SQLServerClass(); sqlserver.Connect(dbConfig.dbpath, dbConfig.userid, dbConfig.password); try { if (File.Exists(mapPath + "\\" + dbConfig.dbname + ".bak")) { File.Delete(mapPath + "\\" + dbConfig.dbname + ".bak"); } ((_Backup) new BackupClass { Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database, Initialize = true, Files = mapPath + "\\" + dbConfig.dbname + ".bak", Database = dbConfig.dbname }).SQLBackup(sqlserver); if (File.Exists(mapPath + "\\" + str + ".config")) { using (FPZip fpzip = new FPZip()) { fpzip.AddFile(mapPath + "\\" + dbConfig.dbname + ".bak", dbConfig.dbname + ".bak"); fpzip.ZipSave(mapPath + "\\" + str + ".config"); } File.Delete(mapPath + "\\" + dbConfig.dbname + ".bak"); } return(string.Empty); } catch (Exception ex) { string text = ex.Message.Replace("'", " "); text = text.Replace("\n", " "); return(text.Replace("\\", "/")); } finally { sqlserver.DisConnect(); } } string result; try { if (File.Exists(mapPath + "\\" + str + ".config")) { File.Delete(mapPath + "\\" + str + ".zip"); using (FPZip fpzip = new FPZip()) { fpzip.AddFile(WebConfig.WebPath + dbConfig.dbpath, dbConfig.dbpath); fpzip.ZipSave(mapPath + "\\" + str + ".config"); } } result = string.Empty; } catch (Exception ex) { string text = ex.Message.Replace("'", " "); text = text.Replace("\n", " "); text = text.Replace("\\", "/"); result = text; } return(result); }