/// <summary> /// Lấy chuổi kết nối từ file text, thực hiện kết nối thử, gán thông tin lên đối tượng /// </summary> /// <returns></returns> public static void Init() { // Mẫu dữ liệu trên file text //Authentication=SQL Server Authentication //Data Source=VAIO\SQLEXPRESS2005 //Initial Catalog=CplusWinformApp1 //User ID=SQL Server Authentication //Password=123456 IList <string> ilstConnInfo = new List <string>(); ilstConnInfo = TextInfo.IListReadLine(GlobalObjects.ApplicationPaths.Logs + @"\ConnectInfo_log.txt"); foreach (string list in ilstConnInfo) { string[] separator = { "=" }; string[] arrConnInfo = list.Split(separator, StringSplitOptions.RemoveEmptyEntries); switch (arrConnInfo[0].ToString()) { case "Authentication": _authentication = arrConnInfo[1].ToString(); break; case "Data Source": _serverName = arrConnInfo[1].ToString(); break; case "Initial Catalog": _databaseName = arrConnInfo[1].ToString(); break; case "User ID": _login = arrConnInfo[1].ToString(); break; case "Password": _password = arrConnInfo[1].ToString(); break; } } if (_authentication.ToUpper() == WINDOWS_AUTHENTICATION) { _connectString = "Data Source=" + _serverName + ";Initial Catalog=" + _databaseName + ";Integrated Security=True"; } else if (_authentication.ToUpper() == SQL_SERVER_AUTHENTICATION) { _connectString = "Data Source=" + _serverName + ";Initial Catalog=" + _databaseName + ";User ID=" + _login + ";Password=" + _password; } }