public static DBConn getDynaConnection(DateTime dt_inserttime, bool b_create) { DBConn result; lock (DBConnPool._lockdatadb) { string str = ""; if (DBUrl.SERVERMODE) { try { DBConn dBConn = new DBConn(); string cONNECT_STRING = DBUrl.CONNECT_STRING; string[] array = cONNECT_STRING.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); dBConn.con = new MySqlConnection(string.Concat(new string[] { "Database=eco", DBUrl.SERVERID, ";Data Source=", array[0], ";Port=", array[1], ";User Id=", array[2], ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;" })); dBConn.con.Open(); dBConn.setInUse(); DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); result = dBConn; return(result); } catch (Exception e) { DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e, false, " ")); result = null; return(result); } } if (DBUrl.DB_CURRENT_TYPE.ToUpperInvariant().Equals("MYSQL")) { try { DBConn dBConn2 = new DBConn(); dBConn2.con = new MySqlConnection(string.Concat(new object[] { "Database=", DBUrl.DB_CURRENT_NAME, ";Data Source=", DBUrl.CURRENT_HOST_PATH, ";Port=", DBUrl.CURRENT_PORT, ";User Id=", DBUrl.CURRENT_USER_NAME, ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;" })); dBConn2.con.Open(); dBConn2.setInUse(); DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_Success, false); result = dBConn2; return(result); } catch (Exception e2) { DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e2, false, " ")); result = null; return(result); } } try { string text = AppDomain.CurrentDomain.BaseDirectory + "datadb"; if (text[text.Length - 1] != Path.DirectorySeparatorChar) { text += Path.DirectorySeparatorChar; } if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } DateTime.Now.ToString("yyyyMMdd"); dt_inserttime.ToString("yyyyMMdd"); string text2 = text + "datadb_" + dt_inserttime.ToString("yyyyMMdd") + ".mdb"; if (!File.Exists(text2) && b_create) { string sourceFileName = text + "datadb.org"; File.Copy(sourceFileName, text2, true); } bool flag2 = false; try { DBConn dBConn3 = new DBConn(); try { dBConn3.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text2 + ";Jet OLEDB:Database Password=root"); dBConn3.con.Open(); flag2 = true; } catch (Exception ex) { str = ex.Message + "\r\n" + ex.StackTrace; int i = 0; while (i < 4) { Thread.Sleep(10); i++; try { dBConn3.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text2 + ";Jet OLEDB:Database Password=root"); dBConn3.con.Open(); flag2 = true; break; } catch (Exception ex2) { str = ex2.Message + "\r\n" + ex2.StackTrace; } } } if (flag2) { dBConn3.setInUse(); dBConn3.DBSource_Type = 2; try { StackTrace stackTrace = new StackTrace(); MethodBase method = stackTrace.GetFrame(1).GetMethod(); DBCache.OpenDataDB(dBConn3.GetHashCode(), method.Name); DBCache.PrintDataDB(); } catch { } result = dBConn3; } else { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + str); result = null; } } catch (Exception ex3) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + ex3.Message + "\n" + ex3.StackTrace); result = null; } } catch (Exception ex4) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + ex4.Message + "\n" + ex4.StackTrace); result = null; } } return(result); }
private static void preparedatadb() { if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL")) { DbCommand dbCommand = null; DbDataReader dbDataReader = null; DBConn dBConn = new DBConn(); try { dBConn.con = new MySqlConnection(string.Concat(new object[] { "Database=", DBUrl.DB_CURRENT_NAME, ";Data Source=", DBUrl.CURRENT_HOST_PATH, ";Port=", DBUrl.CURRENT_PORT, ";User Id=", DBUrl.CURRENT_USER_NAME, ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;" })); dBConn.con.Open(); dBConn.setInUse(); dbCommand = dBConn.con.CreateCommand(); dbCommand.CommandText = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES where (table_name like '%_auto_info%' or table_name like '%_data_daily%' or table_name like '%_data_hourly%' or table_name like 'rackthermal_hourly20%' or table_name like 'rackthermal_daily20%') and table_schema = '" + DBUrl.DB_CURRENT_NAME + "' "; dbDataReader = dbCommand.ExecuteReader(); while (dbDataReader.Read()) { string text = Convert.ToString(dbDataReader.GetValue(0)); if (!DBTools.ht_tablename.ContainsKey(text)) { DBTools.ht_tablename.Add(text, text); } } dbDataReader.Close(); dbCommand.Dispose(); dBConn.Close(); } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + ex.Message + "\n" + ex.StackTrace); try { dbDataReader.Close(); } catch (Exception) { } try { dbCommand.Dispose(); } catch (Exception) { } try { dBConn.Close(); } catch (Exception) { } } } }
public static DBConn getLogConnection() { string str = ""; DBConn result; if (DBUrl.SERVERMODE) { try { DBConn dBConn = new DBConn(); string cONNECT_STRING = DBUrl.CONNECT_STRING; string[] array = cONNECT_STRING.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); dBConn.con = new MySqlConnection(string.Concat(new string[] { "Database=eco", DBUrl.SERVERID, ";Data Source=", array[0], ";Port=", array[1], ";User Id=", array[2], ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;" })); dBConn.con.Open(); dBConn.setInUse(); result = dBConn; return(result); } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get LogDB Connection Error : " + ex.Message + "\n" + ex.StackTrace); result = null; return(result); } } bool flag = false; DBConn dBConn2 = new DBConn(); try { try { dBConn2.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "logdb.mdb;Jet OLEDB:Database Password=ecoSensorlog"); dBConn2.con.Open(); flag = true; } catch (Exception ex2) { str = ex2.Message + "\r\n" + ex2.StackTrace; int i = 0; while (i < 4) { Thread.Sleep(10); i++; try { dBConn2.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "logdb.mdb;Jet OLEDB:Database Password=ecoSensorlog"); dBConn2.con.Open(); flag = true; break; } catch (Exception ex3) { str = ex3.Message + "\r\n" + ex3.StackTrace; } } } if (flag) { dBConn2.setInUse(); result = dBConn2; } else { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get LogDB Connection Error : " + str); result = null; } } catch (Exception ex4) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get LogDB Connection Error : " + ex4.Message + "\n" + ex4.StackTrace); result = null; } return(result); }