// public static string FileName = "SEC.INI"; /// <summary> /// 连接数据库 /// </summary> /// <return>bool</return> public static bool GF_DbConnect() { try { // OleDbConnection Conn = new OleDbConnection(); string Filename = "SEC.ini"; string iniConnectString = string.Empty; string sPath = System.IO.Directory.GetCurrentDirectory(); string sFile = sPath + "\\" + Filename; SecuritySet Security = new SecuritySet(); IniFiles ini = new IniFiles(sFile); string conn = string.Empty; INIAccess iniacc = new INIAccess(); //string strConn = string.Empty; if (OleDbConn.State != System.Data.ConnectionState.Open) { OleDbConn.Close(); } if (OleDbConn_Log.State != ConnectionState.Closed) { OleDbConn_Log.Close(); } OleDbConn.Dispose(); OleDbConn_Log.Dispose(); //Security.DESMain(); NameValueCollection values = new NameValueCollection(); ini.ReadSectionValues("SecuritySet", values); string iniServerName = values["iniServerName"]; string iniUserName = values["iniUserName"]; string iniProvider = values["iniProvider"]; //Security.PwdTrans(values["iniPassWord"], "S"); string iniPassWord = Security.PwdTrans(values["iniPassWord"], "S"); if (Security.KeyGen("Key") && Security.KeyGen("IV")) { iniConnectString = "Provider=" + iniProvider + ";User ID=" + iniUserName + "/" + iniPassWord + "" + ";Data Source=" + iniServerName + ";Persist Security Info=True"; iniConnectString = Security.EncryptString(iniConnectString); } conn = Security.DecryptString(iniConnectString); iniacc.INIWrite(sFile, "SecuritySet", "iniConnectString", iniConnectString.Trim()); if (conn != string.Empty) { OleDbConn.ConnectionString = conn; OleDbConn_Log.ConnectionString = conn; } else { return(false); } // OleDbConn.ConnectionString = conn; if (OleDbConn != null) { if (OleDbConn.State != ConnectionState.Closed) { OleDbConn.Close(); } } if (OleDbConn_Log != null) { if (OleDbConn_Log.State != ConnectionState.Closed) { OleDbConn_Log.Close(); } } //OleDbConn.ConnectionString = strConn; //Conn.ConnectionString = strConn; try { // Conn.Open(); OleDbConn.Open();// = Conn; OleDbConn_Log.Open(); } catch { return(false); } return(true); } catch (Exception ex) { Gp_MsgBoxDisplay("服务器链接有错误...!!!" + ex.Message, "W", "DataBase Connection"); return(false); } }