예제 #1
0
        public static DBConn getConnection()
        {
            DBConn result;

            lock (DBConnPool._locksysdb)
            {
                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();
                        result = dBConn;
                        return(result);
                    }
                    catch (Exception ex)
                    {
                        DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get SysDB Connection Error : " + ex.Message + "\n" + ex.StackTrace);
                        result = null;
                        return(result);
                    }
                }
                bool flag2 = false;
                try
                {
                    DBConn dBConn2 = new DBConn();
                    try
                    {
                        dBConn2.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "sysdb.mdb;Jet OLEDB:Database Password=^tenec0Sensor");
                        dBConn2.con.Open();
                        flag2 = 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 + "sysdb.mdb;Jet OLEDB:Database Password=^tenec0Sensor");
                                dBConn2.con.Open();
                                flag2 = true;
                                break;
                            }
                            catch (Exception ex3)
                            {
                                str = ex3.Message + "\r\n" + ex3.StackTrace;
                            }
                        }
                    }
                    if (flag2)
                    {
                        dBConn2.setInUse();
                        dBConn2.DBSource_Type = 1;
                        try
                        {
                            StackTrace stackTrace = new StackTrace();
                            MethodBase method     = stackTrace.GetFrame(1).GetMethod();
                            DBCache.OpenSysDB(dBConn2.GetHashCode(), method.Name);
                            DBCache.PrintSysDB();
                        }
                        catch
                        {
                        }
                        result = dBConn2;
                    }
                    else
                    {
                        DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get SysDB Connection Error : " + str);
                        DBCache.PrintSysDB();
                        result = null;
                    }
                }
                catch (Exception ex4)
                {
                    DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get SysDB Connection Error : " + ex4.Message + "\n" + ex4.StackTrace);
                    DBCache.PrintSysDB();
                    result = null;
                }
            }
            return(result);
        }