/// <summary> /// 备份数据库配置文件 /// </summary> /// <param name="bci"></param> /// <returns></returns> public static bool BackupBaseConfig(BaseConfigInfo bci) { try { if (!Directory.Exists(HttpContext.Current.Server.MapPath("/_Temp"))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/_Temp")); } BaseConfigs.SaveConfigTo(bci, HttpContext.Current.Server.MapPath("/_Temp/db.config")); return(true); } catch { return(false); } }
private bool SaveDBConfig(BaseConfigInfo bci) { try { string file = Server.MapPath("~/config/db.config"); BaseConfigs.SaveConfigTo(bci, file); BaseConfigs.ResetConfig(); SetupPage.CreateLockFile(); return(true); } catch { ErrProcess(bci); } return(false); }
private void ResetDBInfo_Click(object sender, EventArgs e) { CreateDataLogPath(); if (GenerateConfigCheckbox.Checked) { string configPath = Server.MapPath("~/config/db.config"); BaseConfigs.SaveConfigTo(DBConfig, configPath); BaseConfigs.ResetConfig(); } //读取默认db.config文件内容 BaseConfigInfo bci = BaseConfigs.GetBaseConfig(); if (bci != null && bci.DBType != "" && bci.DBConnectionString != "") { Installer.ExcuteSQLGroup(bci); this.Response.Redirect("succeed.aspx"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('无法读取数据库配置文件db.config,请检查重试。');</script>"); } }
[SoapHeader("header")] //用户身份验证的soap header public string InitDBConfig(string setupDbType, DatabaseInfo dbi) { //验证是否有权访问(当然,也可以通过查询数据库实现,具体视项目要求) if (!CheckAdmin(header.UserName, header.PassWord)) { throw new Exception("无权使用此服务"); } string source = "We7.CMS.Install-InstallWebService-SetSiteConfig"; try { BaseConfigInfo baseConfig = Installer.GenerateConnectionString(setupDbType, dbi); string file = Server.MapPath("~/config/db.config"); BaseConfigs.SaveConfigTo(baseConfig, file); BaseConfigs.ResetConfig(); if (dbi.CreateDB) { Exception ex = null; int ret = Installer.CreateDatabase(baseConfig, out ex); if (ret == -1) { string msg = "数据库已存在,请重新命名或去掉重新“创建新数据库”前面的勾,使用已有数据库。"; Exception ex1 = new Exception(msg); EventLogHelper.WriteToLog(source, ex1, EventLogEntryType.Error); return(msg); } else if (ret == 0) { string exceptionMsgs = ex.Message; EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); return("创建数据库发生错误。错误原因:" + exceptionMsgs); } } //设置数据库脚本路径 //string basePath = Server.MapPath("/install/SQL"); //if (!Directory.Exists(basePath)) //{ // basePath = Server.MapPath("../install/SQL"); //} if (!Directory.Exists(Server.MapPath("/_data/"))) { Directory.CreateDirectory(Server.MapPath("/_data/")); } List <string> files = new List <string>(); files.Add("create.xml"); files.Add("install.xml"); files.Add("update.xml"); Installer.ExcuteSQLGroup(baseConfig, files); //创建内容模型表 Installer.CreateModelTables(); ApplicationHelper.ResetApplication(); return("0"); } catch (Exception ex) { EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); return("创建数据库发生错误。错误原因:" + ex.Message); } }