Наследование: IDisposable
Пример #1
0
        public static void Refresh()
        {
            String dbName = Starter.CustomData.GetValue("SystemDB/dbname");
            String dbHost = Starter.CustomData.GetValue("SystemDB/ipaddress");
            Int32 dbPort = Starter.CustomData.GetValue("SystemDB/portno").ToInt32();
            String userId = Starter.CustomData.GetValue("SystemDB/userid");
            String userPwd = Starter.CustomData.GetValue("SystemDB/userpwd");

            ConnectionPool systemDB = new ConnectionPool(dbHost, dbPort, "", dbName, userId, userPwd);
            using (DBCommand cmd = new DBCommand(systemDB))
            {
                cmd.CommandText.Append("select uid, worldid, dbtype, dbname, ipaddress, portno, userid, passwd");
                cmd.CommandText.Append(", charset, shardkey_start, shardkey_end");
                cmd.CommandText.Append(" from t_listdb;");
                MySqlDataReader reader = cmd.Query();

                while (reader.Read())
                {
                    DBInfo info = new DBInfo()
                    {
                        Uid = reader.GetInt32(0),
                        WorldId = reader.GetInt32(1),
                        DBType = (DBType)reader.GetInt32(2),
                        DBName = reader.GetString(3),
                        IPAddress = reader.GetString(4),
                        PortNo = reader.GetInt32(5),
                        UserId = reader.GetString(6),
                        UserPwd = reader.GetString(7),
                        CharSet = (reader.IsDBNull(8) == true ? "" : reader.GetString(8)),
                        ShardKeyStart = (reader.IsDBNull(9) == true ? 0 : reader.GetInt32(9)),
                        ShardKeyEnd = (reader.IsDBNull(10) == true ? 0 : reader.GetInt32(10))
                    };
                    Items.Add(info);

                    if (info.DBType == DBType.System)
                        SystemDB.Initialize(info);

                    else if (info.DBType == DBType.Auth)
                        AuthDB.Initialize(info);

                    else if (info.DBType == DBType.Game)
                        GameDB.AddDBInfo(info);
                }
            }
            systemDB.Release();
        }