Ejemplo n.º 1
0
        private static void ClearUpdate()
        {
            DbHelperForMysql dbhelper = new DbHelperForMysql(DALConfig.CoreConnString);
            string           sql      = "update connectionChgLog set status = 0 where status = 1";

            dbhelper.ExecuteNonQuery(sql);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取连接字符串列表
        /// </summary>
        /// <returns></returns>
        private static void InitConn()
        {
            //key =  分区号-库名-读写   从数据库读取
            //Dictionary<string, List<ConnectionConfig>> dic = new Dictionary<string, List<ConnectionConfig>>();
            DbHelperForMysql dbhelper = new DbHelperForMysql(DALConfig.CoreConnString);
            string           sql      = "select * from connectionconfig where status=1";
            DataSet          ds       = dbhelper.ExecuteDataSet(sql);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                _hashConn.Clear();//清空
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow          row    = ds.Tables[0].Rows[i];
                    ConnectionConfig config = new ConnectionConfig();
                    config.DBID          = Convert.ToInt32(row["ID"]);
                    config.ShardID       = Convert.ToInt32(row["ShardID"]);
                    config.DBName        = row["DBName"].ToString();
                    config.DBType        = (DBType)Enum.Parse(typeof(DBType), row["DBType"].ToString());
                    config.ReadWriteType = Convert.ToInt32(row["ReadWriteType"]);

                    config.ConnectionString = row["ConnectionString"].ToString()
                                              + (DALConfig.AllowUserVariables ? ";AllowUserVariables=true" : null);
                    config.LogEnable = Convert.ToBoolean(row["LogEnable"]);


                    string key = string.Format("{0}_{1}_{2}", config.ShardID, config.DBName, config.ReadWriteType).ToLower();
                    if (!_hashConn.ContainsKey(key))
                    {
                        _hashConn.Add(key, new List <ConnectionConfig>());
                    }
                    ((List <ConnectionConfig>)_hashConn[key]).Add(config);
                }
            }
        }
Ejemplo n.º 3
0
        private static bool CheckUpdate()
        {
            DbHelperForMysql dbhelper     = new DbHelperForMysql(DALConfig.CoreConnString);
            string           sql          = "select 1 from connectionChgLog where status = 1";
            bool             existsUpdate = dbhelper.Exists(sql);

            return(existsUpdate);
        }