public static IList <DbConfigInfo> ReadDBInfo() { IList <DbConfigInfo> dbConfigList = new List <DbConfigInfo>(); try { var dataSet = new DataSet(); db.Fill("select * from db_plugin_config", dataSet); foreach (DataRow row in dataSet.Tables[0].Rows) { var dbConfigInfo = new DbConfigInfo(); dbConfigInfo.DbType = row["dbtype"] + ""; dbConfigInfo.DbConfigName = row["dbName"] + ""; dbConfigInfo.ConnectionString = row["dbConnectionString"] + ""; dbConfigInfo.DbEncoder = row["dbEncoder"] + ""; dbConfigInfo.DbId = row["dbId"] + ""; dbConfigList.Add(dbConfigInfo); } } catch (Exception ex) { LogHelper.Error(ex); } return(dbConfigList); }
static void Main() { string Query = "SELECT * FROM [MyTable]"; //db connection config DbConfigInfo Config = new DbConfigInfo() { ServerAddress = "MyServer", DbName = "MyDb", TrustedConnection = true }; //db adapter for communication DbAdapter Adapter = new DbAdapter() { DbConfig = Config }; //output with data DataTable MyDataTable; if (!Adapter.ExecuteSqlCommandAsTable(Query, out MyDataTable)) { Console.WriteLine("Error Occured!"); Console.ReadLine(); return; } //do actions with your DataTable }
public OracleDBConfigForm(DbConfigInfo dbConfigInfo) : this() { btnAdd.Text = "删除"; btnUpdate.Visible = true; setDbConfigInfo(dbConfigInfo); }
void BackgroundWorkerLoadDbRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (_isLoadSuccess) { DbConfigInfo dbConfigInfo = GetCurenctDbConfigInfo(); if (dbConfigInfo != null) { if (_dsTable.Tables.Count == 0) { SetStatusBar(string.Format("{0}数据加载完毕,共{1}表", dbConfigInfo.DbConfigName, 0)); } foreach (DataTable dt in _dsTable.Tables) { if (dt.TableName.Equals(dbConfigInfo.DbConfigName + Tables)) { SetStatusBar(string.Format("{0}数据加载完毕,共{1}表", dbConfigInfo.DbConfigName, _dsTable.Tables[dbConfigInfo.DbConfigName + Tables].Rows.Count)); } } } registerObject(PluginShareHelper.DBCurrentDBAllTable, _dsTable); registerObject(PluginShareHelper.DBCurrentDBAllTablesColumns, _dsTableColumn); registerObject(PluginShareHelper.DBCurrentDBTablesPrimaryKeys, _dsTablePrimaryKey); SetEnable(true); } else { SetEnable(true); SetTbDbEnable(false); } }
private void btnTestConnection_Click(object sender, EventArgs e) { try { if (checkData()) { ThreadPool.QueueUserWorkItem(o => { DbConfigInfo dbConfigInfo = getDbConfigInfo(); string conString = dbConfigInfo.ConnectionString.Trim(new char[] { '"' }); string dbProvider = DBType.GetDbProviderString(dbConfigInfo.DbType); DNCCFrameWork.DataAccess.IDbHelper db = new DNCCFrameWork.DataAccess.DbFactory(conString, dbProvider). IDbHelper; bool success = db.TestConnection(); string tip = "数据库连接失败"; if (success) { tip = "数据库连接成功"; } MessageBox.Show(this, tip, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); }); } } catch (System.Data.Common.DbException ex) { MessageBox.Show(this, ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
private void AddNodes(TreeNodeCollection collection) { if (_mainTool.InvokeRequired) { var s = new CreateRootNodeDel(AddNodes); _mainTool.Invoke(s, new object[] { collection }); } else { DbConfigInfo dbConfigInfo = GetCurenctDbConfigInfo(); if (dbConfigInfo != null) { for (int i = 0; i < _dsTable.Tables.Count; i++) { if (_dsTable.Tables[i].TableName.Equals(dbConfigInfo.DbConfigName + Tables)) { AddNodes(collection[0].Nodes, _dsTable.Tables[i]); } if (_dsTable.Tables[i].TableName.Equals(dbConfigInfo.DbConfigName + Views)) { AddNodes(collection[1].Nodes, _dsTable.Tables[i]); } } } } }
// 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 bool InsertConfig(DbConfigInfo info) { var xmlNode = _xmlHelper.SerializeXmlNode(info); _xmlHelper.AppendNode(xmlNode); _xmlHelper.Save(); return(true); }
private void btnUpdate_Click(object sender, EventArgs e) { if (checkData()) { DbConfigInfo = getDbConfigInfo(); dialogResult = DialogResult.Yes; Close(); } }
private void setDbConfigInfo(DbConfigInfo dbConfigInfo) { dbId = dbConfigInfo.DbId; teServerName.Text = dbConfigInfo.DbServerName; teUserName.Text = dbConfigInfo.DbUserName; teUserPwd.Text = dbConfigInfo.DbUserPwd; teConfigName.Text = dbConfigInfo.DbConfigName; tbDbEncoder.Text = dbConfigInfo.DbEncoder; teConfigName.ReadOnly = true; }
// 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); }
private DbConfigInfo GetCurenctDbConfigInfo() { DbConfigInfo dbConfigInfo = null; string dbConfigName = GetCurrentDBName(); if (!string.IsNullOrEmpty(dbConfigName) && _dbConfigDic.ContainsKey(dbConfigName)) { dbConfigInfo = _dbConfigDic[dbConfigName]; } return(dbConfigInfo); }
// 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(); } }
private DbConfigInfo getDbConfigInfo() { DbConfigInfo dbConfigInfo = new DbConfigInfo(); dbConfigInfo.DbId = dbId; dbConfigInfo.DbServerName = teServerName.Text.Trim(); dbConfigInfo.DbUserName = teUserName.Text.Trim(); dbConfigInfo.DbUserPwd = teUserPwd.Text.Trim(); dbConfigInfo.DbType = "Oracle"; dbConfigInfo.DbConfigName = teConfigName.Text.Trim(); dbConfigInfo.DbEncoder = tbDbEncoder.Text.Trim(); return(dbConfigInfo); }
private void tvDBConfig_MouseDoubleClick(object sender, MouseEventArgs e) { var text = tvDBConfig.SelectedNode.Text as string; switch (text) { case "Oracle": OracleDBConfigForm of = new OracleDBConfigForm(); of.ShowDialog(this); if (of.DialogResult.Equals(DialogResult.OK)) { dbConfigInfos.Insert(0, of.DbConfigInfo); createTreeNode(); isChanged = true; } break; default: DbConfigInfo dbConfigInfo = tvDBConfig.SelectedNode.Tag as DbConfigInfo; if (dbConfigInfo != null) { if (dbConfigInfo.DbType == "Oracle") { OracleDBConfigForm of2 = new OracleDBConfigForm(dbConfigInfo); of2.ShowDialog(this); if (of2.DialogResult.Equals(DialogResult.OK)) { dbConfigInfo.IsDelete = true; createTreeNode(); isChanged = true; } else if (of2.DialogResult.Equals(DialogResult.Yes)) { dbConfigInfos.Remove(dbConfigInfo); dbConfigInfos.Insert(0, of2.DbConfigInfo); isChanged = true; } } } break; } }
public static bool WriteDBInfo(DbConfigInfo dbConfigInfo, ref string message) { bool status = false; if (dbConfigInfo != null) { try { var dic = new Dictionary <string, string>(); string sql = ""; if (dbConfigInfo.IsDelete) { sql = "delete from db_plugin_config where dbId=@dbId"; dic.Add("@dbId", dbConfigInfo.DbId); } else { dic.Add("@dbName", dbConfigInfo.DbConfigName); dic.Add("@dbConnectionString", dbConfigInfo.ConnectionString); dic.Add("@dbType", dbConfigInfo.DbType); dic.Add("@dbEncoder", dbConfigInfo.DbEncoder); if (string.IsNullOrEmpty(dbConfigInfo.DbId)) { dic.Add("@dbId", Guid.NewGuid().ToString()); sql = "INSERT INTO db_plugin_config(dbId, dbName, dbConnectionString, dbType, dbEncoder) VALUES(@dbId, @dbName, @dbConnectionString, @dbType, @dbEncoder)"; } else { dic.Add("@dbId", dbConfigInfo.DbId); sql = "update db_plugin_config set dbName=@dbName,dbConnectionString=@dbConnectionString,dbType=@dbType,dbEncoder=@dbEncoder where dbId=@dbId"; } } db.ExecuteNonQuery(sql, dic); status = true; } catch (Exception ex) { LogHelper.Error(ex); message = ex.Message; } } return(status); }
private void LoadDatas() { _dbConfigInfos = new List <DbConfigInfo>(); var nodes = _xmlHelper.GetNode("/databases").ChildNodes; foreach (XmlNode node in nodes) { var dbconfigInfo = new DbConfigInfo() { Id = node.SelectSingleNode("./Id").InnerText, DbSourceName = node.SelectSingleNode("./DbSourceName").InnerText, DbConnectionString = node.SelectSingleNode("./DbConnectionString").InnerText, DbSourceServicePwd = node.SelectSingleNode("./DbSourceServicePwd").InnerText, DbSourceServiceName = node.SelectSingleNode("./DbSourceServiceName").InnerText, DbSourceAddress = node.SelectSingleNode("./DbSourceAddress").InnerText, }; _dbConfigInfos.Add(dbconfigInfo); } }
// 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); }
private void button11_Click(object sender, EventArgs e) { if (button11.Text == "保存该链接") { string errorMsg = String.Empty; if (!ValidDbConfig(out errorMsg)) { MessageTip(errorMsg); return; } var config = new DbConfigInfo() { DbSourceName = txtDbSourceName.Text.Trim(), DbConnectionString = rtxDbConnStr.Text.Trim(), DbSourceAddress = txtDbAddress.Text.Trim(), DbSourceServiceName = txtDbServiceUserName.Text.Trim(), DbSourceServicePwd = txtDbServicePwd.Text.Trim() }; _dbConfigInfoDal.InsertConfig(config); LoadDbConfigInfo(); MessageTip("保存成功"); button11.Text = "重置"; } else if (button11.Text == "重置") { isConnection = false; button11.Text = "保存该链接"; txtDbSourceName.Text = string.Empty; txtDbSourceName.Enabled = true; rtxDbConnStr.Text = string.Empty; rtxDbConnStr.Enabled = true; txtDbServiceUserName.Text = string.Empty; txtDbServiceUserName.Enabled = true; txtDbServicePwd.Text = string.Empty; txtDbServicePwd.Enabled = true; } }
public static bool WriteDefaultDBInfo(DbConfigInfo dbConfigInfo) { bool status = false; if (dbConfigInfo != null) { try { var dic = new Dictionary <string, string>(); dic.Add("@dbId", dbConfigInfo.DbId); string delSql = "delete from db_plugin_defaultSelect"; int result = db.ExecuteNonQuery(delSql); string insertSql = "INSERT INTO db_plugin_defaultSelect(dbId) VALUES(@dbId)"; result = db.ExecuteNonQuery(insertSql, dic); status = true; } catch (Exception ex) { LogHelper.Error(ex); } } return(status); }
private void LoadDbInfoBySync(bool reloadDb) { _isLoadSuccess = false; DbConfigInfo dbConfigInfo = GetCurenctDbConfigInfo(); IniConfigHelper.WriteDefaultDBInfo(dbConfigInfo); string TargetEncoding = ""; string OriginalEncoding = ""; if (dbConfigInfo != null) { try { #region 贡献当前数据库配置信息 TargetEncoding = dbConfigInfo.DbEncoder; OriginalEncoding = EncodingHelper.OriginalEncoding; registerObject(PluginShareHelper.TargetEncoding, TargetEncoding); registerObject(PluginShareHelper.OriginalEncoding, OriginalEncoding); registerObject(PluginShareHelper.DBCurrentDBName, dbConfigInfo.DbConfigName); registerObject(PluginShareHelper.DBCurrentDBConnectionString, dbConfigInfo.ConnectionString.Trim('"')); registerObject(PluginShareHelper.DBCurrentDBType, dbConfigInfo.DbType); #endregion #region 加载所有表信息 SetStatusBar(string.Format("正在获取{0}中所有表信息", dbConfigInfo.DbConfigName)); SetProgress(0); if (_dsTable.Tables.Contains(dbConfigInfo.DbConfigName + Tables)) { _dsTable.Tables.Remove(dbConfigInfo.DbConfigName + Tables); } #region 从本地读取数据 bool status = DBFileHelper.IsExist(dbConfigInfo.DbConfigName, Tables); if (!reloadDb) { if (status) { DBFileHelper.ReadXml(_dsTable, dbConfigInfo.DbConfigName, Tables); } } #endregion #region 从数据库中读取数据 if (!status || reloadDb) { DNCCFrameWork.DataAccess.IDbHelper db = new DNCCFrameWork.DataAccess.DbFactory(dbConfigInfo.ConnectionString.Trim(new[] { '"' }), DBType.GetDbProviderString(dbConfigInfo.DbType)).IDbHelper; string sql = SqlDefHelper.GetTableNames(dbConfigInfo.DbType); DataSet temp = new DataSet(); db.Fill(sql, temp, new[] { dbConfigInfo.DbConfigName + Tables }); temp = DBFileHelper.WriteXml(temp, OriginalEncoding, TargetEncoding);//缓存表数据到本地 _dsTable.Merge(temp); } #endregion SetStatusBar(string.Format("{0}所有表信息加载完毕", dbConfigInfo.DbConfigName)); SetProgress(10); #endregion #region 加载所有表主键 SetStatusBar(string.Format("正在获取{0}中所有表主键信息", dbConfigInfo.DbConfigName)); if (_dsTablePrimaryKey.Tables.Contains(dbConfigInfo.DbConfigName + TablesPrimaryKeys)) { _dsTablePrimaryKey.Tables.Remove(dbConfigInfo.DbConfigName + TablesPrimaryKeys); } #region 从本地读取数据 status = DBFileHelper.IsExist(dbConfigInfo.DbConfigName, TablesPrimaryKeys); if (!reloadDb) { if (status) { DBFileHelper.ReadXml(_dsTablePrimaryKey, dbConfigInfo.DbConfigName, TablesPrimaryKeys); } } #endregion #region 从数据库中读取数据 if (!status || reloadDb) { DNCCFrameWork.DataAccess.IDbHelper db = new DNCCFrameWork.DataAccess.DbFactory(dbConfigInfo.ConnectionString.Trim(new[] { '"' }), DBType.GetDbProviderString(dbConfigInfo.DbType)).IDbHelper; string sql = SqlDefHelper.GetAllTablePrimaryKeys(dbConfigInfo.DbType); DataSet temp = new DataSet(); db.Fill(sql, temp, new[] { dbConfigInfo.DbConfigName + TablesPrimaryKeys }); temp = DBFileHelper.WriteXml(temp, OriginalEncoding, TargetEncoding);//缓存表数据到本地 _dsTablePrimaryKey.Merge(temp); } #endregion SetStatusBar(string.Format("{0}所有表主键信息加载完毕", dbConfigInfo.DbConfigName)); SetProgress(10); #endregion #region 构造树形结构 BindTreeBySync(); #endregion #region 加载所有表字段信息 SetStatusBar(string.Format("正在获取{0}中所有表字段信息", dbConfigInfo.DbConfigName)); if (_dsTableColumn.Tables.Contains(dbConfigInfo.DbConfigName + TablesColumns)) { _dsTableColumn.Tables.Remove(dbConfigInfo.DbConfigName + TablesColumns); } #region 从本地读取表字段信息 status = DBFileHelper.IsExist(dbConfigInfo.DbConfigName, TablesColumns); if (!reloadDb) { if (status) { DBFileHelper.ReadXml(_dsTableColumn, dbConfigInfo.DbConfigName, TablesColumns); SetProgress(80); } } #endregion #region 从数据库读取表字段信息 if (!status || reloadDb) { DNCCFrameWork.DataAccess.IDbHelper db = new DNCCFrameWork.DataAccess.DbFactory(dbConfigInfo.ConnectionString.Trim(new[] { '"' }), DBType.GetDbProviderString(dbConfigInfo.DbType)).IDbHelper; int count = _dsTable.Tables[dbConfigInfo.DbConfigName + Tables].Rows.Count; if (count != 0) { int temp1 = count / 7; bool isDivisible = count % temp1 == 0; string sql = SqlDefHelper.GetTableColumnNames(dbConfigInfo.DbType); DataSet dsTemp = new DataSet(); for (int i = 0; i < count; i++) { DataRow dr = _dsTable.Tables[dbConfigInfo.DbConfigName + Tables].Rows[i]; var temp = new DataSet(); var dicPar = new Dictionary <string, string> { { "@tableName", dr["name"] as string } }; SetStatusBar(string.Format("正在获取{0}中{1}字段信息", dbConfigInfo.DbConfigName, dr["name"] as string)); db.Fill(sql, temp, new[] { dbConfigInfo.DbConfigName + TablesColumns }, dicPar); dsTemp.Merge(temp); if (i % temp1 == 0) { SetProgress(10); } } dsTemp = DBFileHelper.WriteXml(dsTemp, OriginalEncoding, TargetEncoding); //缓存表字段数据到本地, _dsTableColumn.Merge(dsTemp); if (!isDivisible) { SetProgress(10); } } } #endregion SetEnable(true); #endregion _isLoadSuccess = true; } catch (Exception ex) { SetStatusBar(string.Format("加载数据失败[{0}]", ex.Message)); } } else { SetStatusBar("加载数据失败[没有获取到数据库配置]"); } }
// 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); }
// 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); }