Example #1
0
        public virtual DbConnection GetDbConnection(string connectionString)
        {
            var connSetting = ConnectionStrings.FirstOrDefault(c => c.ConnectionString == connectionString);

            if (connSetting == null)
            {
                throw new Exception("No database config.");
            }
            else
            {
                if (connSetting.MaxPools > 0 && connSetting.MaxPools < connSetting.ActiveConnectionCount)
                {
                    throw new Exception(string.Format("Database connection pool limit for {0}:{1}", connSetting.MaxPools,
                                                      connSetting.ActiveConnectionCount));
                }
            }
            var conn = GetDbConnection();

            conn.ConnectionString = connectionString;
            lock (_countObj)
            {
                connSetting.ActiveConnectionCount++;
            }
            return(conn);
        }
Example #2
0
        private void ActiveConnection(string connectionString, int count)
        {
            var connSetting = ConnectionStrings.FirstOrDefault(c => c.ConnectionString == connectionString);

            if (connSetting != null)
            {
                lock (_countObj)
                {
                    connSetting.ActiveConnectionCount = connSetting.ActiveConnectionCount + count;
                }
            }
        }
Example #3
0
 public virtual string FindConnectionString(string name)
 {
     return(ConnectionStrings.FirstOrDefault(c => c.Name == name)?.Value);
 }
Example #4
0
using JetBrains.Annotations;