/// <summary> /// ��ȡ���ݿ��������ö��� /// </summary> /// <returns></returns> public DataConfig GetDataConfig() { DataConfig config = new DataConfig(); XmlDocument xml = new XmlDocument(); xml.Load(Application.StartupPath + "\\DataConfig\\database.config"); XmlNodeList list = xml.GetElementsByTagName("add"); foreach (XmlNode node in list) { string key = node.Attributes["key"].Value; switch (key) { case "datasource": config.Datasource = node.Attributes["value"].Value; break; case "database": config.Database = node.Attributes["value"].Value; break; case "userid": config.Userid = node.Attributes["value"].Value; break; case "password": config.Password = node.Attributes["value"].Value; break; default: break; } } return config; }
public bool SetDataConfig(DataConfig data) { DataConfig config = new DataConfig(); XmlDocument xml = new XmlDocument(); xml.Load(Application.StartupPath + "\\DataConfig\\database.config"); XmlNodeList list = xml.GetElementsByTagName("add"); foreach (XmlNode node in list) { string key = node.Attributes["key"].Value; switch (key) { case "datasource": node.Attributes["value"].Value = config.Datasource; break; case "database": node.Attributes["value"].Value = config.Database; break; case "userid": node.Attributes["value"].Value= config.Userid ; break; case "password": node.Attributes["value"].Value = config.Password; break; default: break; } } try { xml.Save(Application.StartupPath + "\\DataConfig\\database.config"); } catch { return false; } return true; }
static void SetSystemIni(DataConfig data) { string filename = Application.StartupPath+"\\system.ini"; string conn = string.Format("Provider=SQLOLEDB.1;User ID={0};Password={1};Persist Security Info=True;Initial Catalog={2};Data Source={3}", data.Userid, data.Password, data.Database, data.Datasource); try { Itop.Common.IniFile.IniWriteValue(filename, "ODBC����", "DSN", "BZHZY"); Itop.Common.IniFile.IniWriteValue(filename, "ODBC����", "�û���", data.Userid); Itop.Common.IniFile.IniWriteValue(filename, "ODBC����", "����", data.Password); Itop.Common.IniFile.IniWriteValue(filename, "settings", "Conn", conn); } catch { } }