mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 优化 初始化时若数据库超时,则放弃预热;
This commit is contained in:
parent
eb6244e0ba
commit
766fe901d7
@ -2,6 +2,7 @@
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -59,8 +60,15 @@ namespace FreeSql.MySql {
|
||||
Regex.Replace(connStr, poolsizePatern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) :
|
||||
$"{connStr};Max pool size={PoolSize}";
|
||||
|
||||
var initConns = new Object<DbConnection>[poolsize];
|
||||
for (var a = 0; a < poolsize; a++) try { initConns[a] = _pool.Get(); } catch { }
|
||||
var initConns = new List<Object<DbConnection>>();
|
||||
for (var a = 0; a < PoolSize; a++)
|
||||
try {
|
||||
var conn = _pool.Get();
|
||||
initConns.Add(conn);
|
||||
conn.Value.Ping(true);
|
||||
} catch {
|
||||
break; //预热失败一次就退出
|
||||
}
|
||||
foreach (var conn in initConns) _pool.Return(conn);
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +74,15 @@ namespace FreeSql.Oracle {
|
||||
Regex.Replace(connStr, poolsizePatern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) :
|
||||
$"{connStr};Max pool size={PoolSize}";
|
||||
|
||||
var initConns = new Object<DbConnection>[poolsize];
|
||||
for (var a = 0; a < poolsize; a++) try { initConns[a] = _pool.Get(); } catch { }
|
||||
var initConns = new List<Object<DbConnection>>();
|
||||
for (var a = 0; a < PoolSize; a++)
|
||||
try {
|
||||
var conn = _pool.Get();
|
||||
initConns.Add(conn);
|
||||
conn.Value.Ping(true);
|
||||
} catch {
|
||||
break; //预热失败一次就退出
|
||||
}
|
||||
foreach (var conn in initConns) _pool.Return(conn);
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,15 @@ namespace FreeSql.PostgreSQL {
|
||||
Regex.Replace(connStr, poolsizePatern, $"Maximum pool size={PoolSize}", RegexOptions.IgnoreCase) :
|
||||
$"{connStr};Maximum pool size={PoolSize}";
|
||||
|
||||
var initConns = new Object<DbConnection>[poolsize];
|
||||
for (var a = 0; a < poolsize; a++) try { initConns[a] = _pool.Get(); } catch { }
|
||||
var initConns = new List<Object<DbConnection>>();
|
||||
for (var a = 0; a < PoolSize; a++)
|
||||
try {
|
||||
var conn = _pool.Get();
|
||||
initConns.Add(conn);
|
||||
conn.Value.Ping(true);
|
||||
} catch {
|
||||
break; //预热失败一次就退出
|
||||
}
|
||||
foreach (var conn in initConns) _pool.Return(conn);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
@ -63,8 +64,15 @@ namespace FreeSql.SqlServer {
|
||||
Regex.Replace(connStr, poolsizePatern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) :
|
||||
$"{connStr};Max pool size={PoolSize}";
|
||||
|
||||
var initConns = new Object<DbConnection>[poolsize];
|
||||
for (var a = 0; a < poolsize; a++) try { initConns[a] = _pool.Get(); } catch { }
|
||||
var initConns = new List<Object<DbConnection>>();
|
||||
for (var a = 0; a < PoolSize; a++)
|
||||
try {
|
||||
var conn = _pool.Get();
|
||||
initConns.Add(conn);
|
||||
conn.Value.Ping(true);
|
||||
} catch {
|
||||
break; //预热失败一次就退出
|
||||
}
|
||||
foreach (var conn in initConns) _pool.Return(conn);
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,15 @@ namespace FreeSql.Sqlite {
|
||||
Attaches = (idx == -1 ? att[1] : att[1].Substring(0, idx)).Split(',');
|
||||
}
|
||||
|
||||
var initConns = new Object<DbConnection>[poolsize];
|
||||
for (var a = 0; a < poolsize; a++) try { initConns[a] = _pool.Get(); } catch { }
|
||||
var initConns = new List<Object<DbConnection>>();
|
||||
for (var a = 0; a < PoolSize; a++)
|
||||
try {
|
||||
var conn = _pool.Get();
|
||||
initConns.Add(conn);
|
||||
conn.Value.Ping(true);
|
||||
} catch {
|
||||
break; //预热失败一次就退出
|
||||
}
|
||||
foreach (var conn in initConns) _pool.Return(conn);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user