public static DBConnectionController InitSystemConnection(Guid serverID) { STDataServersController serverCtrl = new STDataServersController(); STDataServersInfo server = serverCtrl.GetObjectByID(serverID) as STDataServersInfo; if (server == null) { return(null); } if (SystemConnections.ContainsKey(serverID)) { if (SystemConnections[serverID].Connection.TestConnection()) { return(SystemConnections[serverID]); } } DBConnectionController connection = new DBConnectionController(server.Name, server.Name); connection.InitNewConnection(server.Name, DatabaseType.MSSQL, server.ServerAddress, server.SystemDatabase, server.UserName, server.EncryptedPassword, false); connection.Connect(); if (connection.Connection.TestConnection()) { SystemConnections.Add(serverID, connection); return(connection); } return(null); }
public static void InitConnectionsFromXML( ) { CompanyCollection.Clear(); SystemCollection.Clear(); String strFileName = @"Config.xml"; XmlDocument doc = new XmlDocument(); doc.Load(strFileName); #region Companys XmlNodeList nodeCompanyList = doc.GetElementsByTagName("Company"); foreach (XmlNode nodeCompany in nodeCompanyList) { String strCompany = nodeCompany.Attributes["Name"].Value.ToString(); String strDesc = nodeCompany.Attributes["Desc"].Value.ToString(); DBConnectionController company = new DBConnectionController(strCompany, strDesc); #region Connection DatabaseType DBType = (DatabaseType)Enum.Parse(typeof(DatabaseType), nodeCompany.Attributes["DBType"].Value.ToString()); String strServer = nodeCompany.Attributes["Server"].Value.ToString(); String strDatabase = nodeCompany.Attributes["Database"].Value.ToString(); String strUser = nodeCompany.Attributes["User"].Value.ToString(); String strPassword = nodeCompany.Attributes["Password"].Value.ToString(); bool isDefault = Convert.ToBoolean(nodeCompany.Attributes["IsDefault"].Value.ToString()); company.InitNewConnection(strCompany, DBType, strServer, strDatabase, strUser, strPassword, isDefault); #endregion if (CompanyCollection.ContainsKey(strCompany) == false) { CompanyCollection.Add(strCompany, company); } } #endregion #region System XmlNodeList nodeSystemList = doc.GetElementsByTagName("System"); foreach (XmlNode nodeSystem in nodeSystemList) { String strSystem = nodeSystem.Attributes["Name"].Value.ToString(); String strDesc = nodeSystem.Attributes["Desc"].Value.ToString(); DBConnectionController System = new DBConnectionController(strSystem, strDesc); #region Connection DatabaseType DBType = (DatabaseType)Enum.Parse(typeof(DatabaseType), nodeSystem.Attributes["DBType"].Value.ToString()); String strServer = nodeSystem.Attributes["Server"].Value.ToString(); String strDatabase = nodeSystem.Attributes["Database"].Value.ToString(); String strUser = nodeSystem.Attributes["User"].Value.ToString(); String strPassword = nodeSystem.Attributes["Password"].Value.ToString(); bool isDefault = Convert.ToBoolean(nodeSystem.Attributes["IsDefault"].Value.ToString()); System.InitNewConnection(strSystem, DBType, strServer, strDatabase, strUser, strPassword, isDefault); #endregion if (SystemCollection.ContainsKey(strSystem) == false) { SystemCollection.Add(strSystem, System); } } #endregion }