/// <summary> /// GetConnectionFromWebConfig - Returns Connection Configuration in web.config file /// </summary> /// <returns>ConnectionConfig object. Null if information is not present in the config file</returns> public ConnectionConfig GetConnectionFromWebConfig() { var connectionConfig = new ConnectionConfig(); string connection = Config.GetConnectionString(); foreach (string connectionParam in connection.Split(';')) { int index = connectionParam.IndexOf("="); if (index > 0) { string key = connectionParam.Substring(0, index); string value = connectionParam.Substring(index + 1); switch (key.ToLower()) { case "server": case "data source": case "address": case "addr": case "network address": connectionConfig.Server = value; break; case "database": case "initial catalog": connectionConfig.Database = value; break; case "uid": case "user id": case "user": connectionConfig.User = value; break; case "pwd": case "password": connectionConfig.Password = value; break; case "integrated security": connectionConfig.Integrated = (value.ToLower() == "true"); break; case "attachdbfilename": connectionConfig.File = value.Replace("|DataDirectory|", ""); break; } } } connectionConfig.Qualifier = Config.GetObjectQualifer(); connectionConfig.RunAsDbowner = Config.GetDataBaseOwner() == "dbo."; connectionConfig.UpgradeConnectionString = Config.GetUpgradeConnectionString(); return connectionConfig; }
/// <summary> /// GetInstallConfig - Returns configuration stored in DotNetNuke.Install.Config /// </summary> /// <returns>ConnectionConfig object. Null if information is not present in the config file</returns> public InstallConfig GetInstallConfig() { var installConfig = new InstallConfig(); //Load Template var installTemplate = new XmlDocument(); Upgrade.GetInstallTemplate(installTemplate); //Parse the root node XmlNode rootNode = installTemplate.SelectSingleNode("//dotnetnuke"); if (rootNode != null) { installConfig.Version = XmlUtils.GetNodeValue(rootNode.CreateNavigator(), "version"); installConfig.InstallCulture = XmlUtils.GetNodeValue(rootNode.CreateNavigator(), "installCulture") ?? Localization.Localization.SystemLocale; } //Parse the scripts node XmlNode scriptsNode = installTemplate.SelectSingleNode("//dotnetnuke/scripts"); if (scriptsNode != null) { foreach (XmlNode scriptNode in scriptsNode) { if (scriptNode != null) { installConfig.Scripts.Add(scriptNode.InnerText); } } } //Parse the connection node XmlNode connectionNode = installTemplate.SelectSingleNode("//dotnetnuke/connection"); if (connectionNode != null) { var connectionConfig = new ConnectionConfig(); //Build connection string from the file connectionConfig.Server = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "server"); connectionConfig.Database = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "database"); connectionConfig.File = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "file"); connectionConfig.Integrated = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "integrated").ToLower() == "true"; connectionConfig.User = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "user"); connectionConfig.Password = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "password"); connectionConfig.RunAsDbowner = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "runasdbowner").ToLower() == "true"; connectionConfig.Qualifier = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "qualifier"); connectionConfig.UpgradeConnectionString = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "upgradeconnectionstring"); installConfig.Connection = connectionConfig; } //Parse the superuser node XmlNode superUserNode = installTemplate.SelectSingleNode("//dotnetnuke/superuser"); if (superUserNode != null) { var superUserConfig = new SuperUserConfig(); superUserConfig.FirstName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "firstname"); superUserConfig.LastName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "lastname"); superUserConfig.UserName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "username"); superUserConfig.Password = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "password"); superUserConfig.Email = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "email"); superUserConfig.Locale = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "locale"); superUserConfig.UpdatePassword = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "updatepassword").ToLower() == "true"; installConfig.SuperUser = superUserConfig; } //Parse the license node XmlNode licenseNode = installTemplate.SelectSingleNode("//dotnetnuke/license"); if (licenseNode != null) { var licenseConfig = new LicenseConfig(); licenseConfig.AccountEmail = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "accountEmail"); licenseConfig.InvoiceNumber = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "invoiceNumber"); licenseConfig.WebServer = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "webServer"); licenseConfig.LicenseType = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "licenseType"); if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "trial"))) { licenseConfig.TrialRequest = bool.Parse(XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "trial")); } installConfig.License = licenseConfig; } //Parse the settings node XmlNode settingsNode = installTemplate.SelectSingleNode("//dotnetnuke/settings"); if (settingsNode != null) { foreach (XmlNode settingNode in settingsNode.ChildNodes) { if (settingNode != null && !string.IsNullOrEmpty(settingNode.Name)) { bool settingIsSecure = false; if (settingNode.Attributes != null) { XmlAttribute secureAttrib = settingNode.Attributes["Secure"]; if ((secureAttrib != null)) { if (secureAttrib.Value.ToLower() == "true") { settingIsSecure = true; } } } installConfig.Settings.Add(new HostSettingConfig {Name = settingNode.Name, Value = settingNode.InnerText, IsSecure = settingIsSecure}); } } } var folderMappingsNode = installTemplate.SelectSingleNode("//dotnetnuke/"+FolderMappingsConfigController.Instance.ConfigNode); installConfig.FolderMappingsSettings = (folderMappingsNode != null)? folderMappingsNode.InnerXml : String.Empty; //Parse the portals node XmlNodeList portalsNode = installTemplate.SelectNodes("//dotnetnuke/portals/portal"); if (portalsNode != null) { foreach (XmlNode portalNode in portalsNode) { if (portalNode != null) { var portalConfig = new PortalConfig(); portalConfig.PortalName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "portalname"); XmlNode adminNode = portalNode.SelectSingleNode("administrator"); if (adminNode != null) { portalConfig.AdminFirstName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "firstname"); portalConfig.AdminLastName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "lastname"); portalConfig.AdminUserName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "username"); portalConfig.AdminPassword = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "password"); portalConfig.AdminEmail = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "email"); } portalConfig.Description = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "description"); portalConfig.Keywords = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "keywords"); portalConfig.TemplateFileName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "templatefile"); portalConfig.IsChild = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "ischild").ToLower() == "true"; ; portalConfig.HomeDirectory = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "homedirectory"); //Get the Portal Alias XmlNodeList portalAliases = portalNode.SelectNodes("portalaliases/portalalias"); if (portalAliases != null) { foreach (XmlNode portalAliase in portalAliases) { if (!string.IsNullOrEmpty(portalAliase.InnerText)) { portalConfig.PortAliases.Add(portalAliase.InnerText); } } } installConfig.Portals.Add(portalConfig); } } } return installConfig; }
/// <summary> /// Tests the Database Connection using the database connection config /// </summary> /// <remarks> /// </remarks> /// <history> /// </history> public string TestDatabaseConnection(ConnectionConfig config) { DbConnectionStringBuilder builder = DataProvider.Instance().GetConnectionStringBuilder(); string owner = string.Empty; string objectQualifier = config.Qualifier; builder["data source"] = config.Server; builder["integrated security"] = config.Integrated; builder["uid"] = config.User; builder["pwd"] = config.Password; if (!string.IsNullOrEmpty(config.File)) { builder["attachDbFilename"] = "|DataDirectory|" + config.File; builder["user instance"] = true; } else { builder["initial catalog"] = config.Database; } if (config.RunAsDbowner) { owner = "dbo."; } return DataProvider.Instance().TestDatabaseConnection(builder, owner, objectQualifier); }
/// ----------------------------------------------------------------------------- /// <summary> /// Page_Init runs when the Page is initialised /// </summary> /// <remarks> /// </remarks> /// <history> /// [cnurse] 02/14/2007 Created /// </history> /// ----------------------------------------------------------------------------- protected override void OnInit(EventArgs e) { base.OnInit(e); //if previous config deleted create new empty one string installConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Install", "DotNetNuke.install.config"); if (!File.Exists(installConfig)) { File.Copy(installConfig + ".resources", installConfig); } GetInstallerLocales(); if (!Page.IsPostBack || _installConfig == null) { _installConfig = InstallController.Instance.GetInstallConfig(); _connectionConfig = _installConfig.Connection; } }
private static void UpdateDatabaseInstallConfig(Dictionary<string, string> installInfo) { // Database Config if (installInfo["databaseSetup"] == "advanced") { _connectionConfig = new ConnectionConfig(); _connectionConfig.Server = installInfo["databaseServerName"]; _connectionConfig.Qualifier = installInfo["databaseObjectQualifier"]; _connectionConfig.Integrated = installInfo["databaseSecurity"] == "integrated"; _connectionConfig.User = installInfo["databaseUsername"]; _connectionConfig.Password = installInfo["databasePassword"]; _connectionConfig.RunAsDbowner = installInfo["databaseRunAsOwner"] == "on"; if (installInfo["databaseType"] == "express") { _connectionConfig.File = installInfo["databaseFilename"]; _connectionConfig.Database = ""; } else { _connectionConfig.Database = installInfo["databaseName"]; _connectionConfig.File = ""; } } _installConfig.Connection = _connectionConfig; InstallController.Instance.SetInstallConfig(_installConfig); }
private static string CheckDatabaseConnection(ConnectionConfig connectionConfig) { _connectionResult = InstallController.Instance.TestDatabaseConnection(connectionConfig); if (_connectionResult.StartsWith("ERROR:")) return _connectionResult; var connectionString = _connectionResult; var details = Localization.Localization.GetString("IsAbleToPerformDatabaseActionsCheck", LocalResourceFile); if (!InstallController.Instance.IsAbleToPerformDatabaseActions(connectionString)) _connectionResult = "ERROR: " + string.Format(Localization.Localization.GetString("IsAbleToPerformDatabaseActions", LocalResourceFile), details); //database actions check-running sql 2008 or higher details = Localization.Localization.GetString("IsValidSqlServerVersionCheck", LocalResourceFile); if (!InstallController.Instance.IsValidSqlServerVersion(connectionString)) _connectionResult = "ERROR: " + string.Format(Localization.Localization.GetString("IsValidSqlServerVersion", LocalResourceFile), details); return _connectionResult; }
private void SetupDatabaseInfo() { //Try to use connection information in DotNetNuke.Install.Config. If not found use from web.config _connectionConfig = _installConfig.Connection; if (_connectionConfig == null || string.IsNullOrEmpty(_connectionConfig.Server)) { _connectionConfig = InstallController.Instance.GetConnectionFromWebConfig(); } if (_connectionConfig != null) { txtDatabaseServerName.Text = _connectionConfig.Server; txtDatabaseObjectQualifier.Text = _connectionConfig.Qualifier; //SQL Express Or SQL Server if (!string.IsNullOrEmpty(_connectionConfig.File)) { txtDatabaseFilename.Text = _connectionConfig.File; databaseType.SelectedIndex = 0; } else { txtDatabaseName.Text = _connectionConfig.Database; databaseType.SelectedIndex = 1; } //Integrated or Custom if (_connectionConfig.Integrated) { databaseSecurityType.SelectedIndex = 0; } else { databaseSecurityType.SelectedIndex = 1; txtDatabaseUsername.Text = _connectionConfig.User; txtDatabasePassword.Text = _connectionConfig.Password; } //Owner or Not databaseRunAs.Checked = _connectionConfig.RunAsDbowner; } }
public static Tuple<bool, string> VerifyDatabaseConnection(Dictionary<string, string> installInfo) { var connectionConfig = new ConnectionConfig(); // Database Config if (installInfo["databaseSetup"] == "standard") { connectionConfig = _connectionConfig; } else { connectionConfig.Server = installInfo["databaseServerName"]; connectionConfig.Qualifier = installInfo["databaseObjectQualifier"]; connectionConfig.Integrated = installInfo["databaseSecurity"] == "integrated"; connectionConfig.User = string.IsNullOrEmpty(installInfo["databaseUsername"]) ? null : installInfo["databaseUsername"]; connectionConfig.Password = string.IsNullOrEmpty(installInfo["databasePassword"]) ? null : installInfo["databasePassword"]; connectionConfig.RunAsDbowner = installInfo["databaseRunAsOwner"] == "on"; if (installInfo["databaseType"] == "express") { connectionConfig.File = installInfo["databaseFilename"]; connectionConfig.Database = ""; } else { connectionConfig.Database = installInfo["databaseName"]; connectionConfig.File = ""; } } var result = CheckDatabaseConnection(connectionConfig); var validConnection = !result.StartsWith("ERROR:"); if (validConnection) { UpdateDatabaseInstallConfig(installInfo); _connectionConfig = connectionConfig; _installConfig.Connection = connectionConfig; } return new Tuple<bool, string>(validConnection, result); }