Example #1
0
        public static string GetConnectionKey(IDbConnection cnn)
        {
            if (string.IsNullOrEmpty(cnn.Database))
            {
                //二级缓存数据库链接字符键值
                string key = GetKey(cnn.ConnectionString);
                if (!string.IsNullOrEmpty(key))
                {
                    return(key);
                }
                else
                {
                    ConnectionStringSet set = GetConnectionStringSet(cnn.ConnectionString);
                    if (set != null)
                    {
                        string dbName = set.UniqueKey;
                        SetKey(cnn.ConnectionString, dbName);
                        return(dbName);
                    }
                }

                return(cnn.ConnectionString);
            }
            else
            {
                return(cnn.Database);
            }
        }
Example #2
0
        public static ConnectionStringSet GetConnectionStringSet(string connStr)
        {
            ConnectionStringSet set;

            if (!SetPool.TryGetValue(connStr, out set))
            {
                string[] result = connStr.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                set = new ConnectionStringSet();
                foreach (string item in result)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        string[] block = item.Split('=');
                        if (block.Length >= 2)
                        {
                            set.Items.Add(block[0].ToUpper(), block[1]);
                        }
                    }
                }

                SetPool[connStr] = set;
            }

            return(set);
        }