diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 7baf32d7..995ea24d 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -4331,7 +4331,7 @@ 不可用时间 - + 将对象池设置为不可用,后续 Get/GetAsync 均会报错,同时启动后台定时检查服务恢复可用 diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs b/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs index f445b499..d150efed 100644 --- a/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs +++ b/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs @@ -88,7 +88,7 @@ namespace FreeSql.Internal.CommonProvider obj.Value.Dispose(); } - public bool SetUnavailable(Exception exception) + public bool SetUnavailable(Exception exception, DateTime lastGetTime) { throw new NotImplementedException(); } @@ -109,7 +109,7 @@ namespace FreeSql.Internal.CommonProvider public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; public DbConnection OnCreate() diff --git a/FreeSql/Internal/ObjectPool/DefaultPolicy.cs b/FreeSql/Internal/ObjectPool/DefaultPolicy.cs index e505e273..2109316e 100644 --- a/FreeSql/Internal/ObjectPool/DefaultPolicy.cs +++ b/FreeSql/Internal/ObjectPool/DefaultPolicy.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace FreeSql.Internal.ObjectPool @@ -16,7 +14,7 @@ namespace FreeSql.Internal.ObjectPool public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; public Func CreateObject; diff --git a/FreeSql/Internal/ObjectPool/IObjectPool.cs b/FreeSql/Internal/ObjectPool/IObjectPool.cs index 45644edb..5a8e896b 100644 --- a/FreeSql/Internal/ObjectPool/IObjectPool.cs +++ b/FreeSql/Internal/ObjectPool/IObjectPool.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace FreeSql.Internal.ObjectPool @@ -25,8 +23,9 @@ namespace FreeSql.Internal.ObjectPool /// 将对象池设置为不可用,后续 Get/GetAsync 均会报错,同时启动后台定时检查服务恢复可用 /// /// + /// /// 由【可用】变成【不可用】时返回true,否则返回false - bool SetUnavailable(Exception exception); + bool SetUnavailable(Exception exception, DateTime lastGetTime); /// /// 统计对象池中的对象 diff --git a/FreeSql/Internal/ObjectPool/Object.cs b/FreeSql/Internal/ObjectPool/Object.cs index cb76a49e..dfa6a6e8 100644 --- a/FreeSql/Internal/ObjectPool/Object.cs +++ b/FreeSql/Internal/ObjectPool/Object.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Threading; namespace FreeSql.Internal.ObjectPool @@ -16,7 +14,8 @@ namespace FreeSql.Internal.ObjectPool Id = id, Value = value, LastGetThreadId = Thread.CurrentThread.ManagedThreadId, - LastGetTime = DateTime.Now + LastGetTime = DateTime.Now, + LastGetTimeCopy = DateTime.Now }; } @@ -42,6 +41,7 @@ namespace FreeSql.Internal.ObjectPool /// 最后获取时的时间 public DateTime LastGetTime { get; internal set; } + public DateTime LastGetTimeCopy { get; internal set; } /// /// 最后归还时的时间 diff --git a/FreeSql/Internal/ObjectPool/ObjectPool.cs b/FreeSql/Internal/ObjectPool/ObjectPool.cs index d2576de3..3440b56f 100644 --- a/FreeSql/Internal/ObjectPool/ObjectPool.cs +++ b/FreeSql/Internal/ObjectPool/ObjectPool.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; using System.Collections.Concurrent; -using System.Linq; +using System.Collections.Generic; using System.Text; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -63,25 +61,23 @@ namespace FreeSql.Internal.ObjectPool public bool IsAvailable => this.UnavailableException == null; public Exception UnavailableException { get; private set; } public DateTime? UnavailableTime { get; private set; } + public DateTime? AvailableTime { get; private set; } private object UnavailableLock = new object(); private bool running = true; - public bool SetUnavailable(Exception exception) + public bool SetUnavailable(Exception exception, DateTime lastGetTime) { - bool isseted = false; - if (exception != null && UnavailableException == null) { - lock (UnavailableLock) { - if (UnavailableException == null) { - + if (lastGetTime < AvailableTime) return false; //已经恢复 UnavailableException = exception; UnavailableTime = DateTime.Now; + AvailableTime = null; isseted = true; } } @@ -89,7 +85,6 @@ namespace FreeSql.Internal.ObjectPool if (isseted) { - Policy.OnUnavailable(); CheckAvailable(Policy.CheckAvailableInterval); } @@ -103,41 +98,31 @@ namespace FreeSql.Internal.ObjectPool /// private void CheckAvailable(int interval) { - new Thread(() => { - if (UnavailableException != null) TestTrace.WriteLine($"【{Policy.Name}】Next recovery time:{DateTime.Now.AddSeconds(interval)}", ConsoleColor.DarkYellow); while (UnavailableException != null) { - if (running == false) return; - Thread.CurrentThread.Join(TimeSpan.FromSeconds(interval)); - if (running == false) return; try { - var conn = GetFree(false); if (conn == null) throw new Exception(CoreStrings.Available_Failed_Get_Resource("CheckAvailable", this.Statistics)); try { - if (Policy.OnCheckAvailable(conn) == false) throw new Exception(CoreStrings.Available_Thrown_Exception("CheckAvailable")); break; - } finally { - Return(conn); } - } catch (Exception ex) { @@ -156,15 +141,13 @@ namespace FreeSql.Internal.ObjectPool bool isRestored = false; if (UnavailableException != null) { - lock (UnavailableLock) { - if (UnavailableException != null) { - UnavailableException = null; UnavailableTime = null; + AvailableTime = DateTime.Now; isRestored = true; } } @@ -172,37 +155,29 @@ namespace FreeSql.Internal.ObjectPool if (isRestored) { - lock (_allObjectsLock) _allObjects.ForEach(a => a.LastGetTime = a.LastReturnTime = new DateTime(2000, 1, 1)); Policy.OnAvailable(); - TestTrace.WriteLine($"【{Policy.Name}】Recovered", ConsoleColor.DarkGreen); } } protected bool LiveCheckAvailable() { - try { - var conn = GetFree(false); if (conn == null) throw new Exception(CoreStrings.Available_Failed_Get_Resource("LiveCheckAvailable", this.Statistics)); try { - if (Policy.OnCheckAvailable(conn) == false) throw new Exception(CoreStrings.Available_Thrown_Exception("LiveCheckAvailable")); - } finally { - Return(conn); } - } catch { @@ -210,7 +185,6 @@ namespace FreeSql.Internal.ObjectPool } RestoreToAvailable(); - return true; } @@ -282,7 +256,6 @@ namespace FreeSql.Internal.ObjectPool if ((_freeObjects.TryPop(out var obj) == false || obj == null) && _allObjects.Count < Policy.PoolSize) { - lock (_allObjectsLock) if (_allObjects.Count < Policy.PoolSize) _allObjects.Add(obj = new Object { Pool = this, Id = _allObjects.Count + 1 }); @@ -310,12 +283,9 @@ namespace FreeSql.Internal.ObjectPool public Object Get(TimeSpan? timeout = null) { - var obj = GetFree(true); - if (obj == null) { - var queueItem = new GetSyncQueueInfo(); _getSyncQueue.Enqueue(queueItem); @@ -336,9 +306,7 @@ namespace FreeSql.Internal.ObjectPool if (obj == null) { - Policy.OnGetTimeout(); - if (Policy.IsThrowGetTimeoutException) throw new TimeoutException(CoreStrings.ObjectPool_Get_Timeout(Policy.Name, "Get", timeout.Value.TotalSeconds)); @@ -358,6 +326,7 @@ namespace FreeSql.Internal.ObjectPool obj.LastGetThreadId = Thread.CurrentThread.ManagedThreadId; obj.LastGetTime = DateTime.Now; + obj.LastGetTimeCopy = DateTime.Now; Interlocked.Increment(ref obj._getTimes); return obj; @@ -367,12 +336,9 @@ namespace FreeSql.Internal.ObjectPool #else async public Task> GetAsync() { - var obj = GetFree(true); - if (obj == null) { - if (Policy.AsyncGetCapacity > 0 && _getAsyncQueue.Count >= Policy.AsyncGetCapacity - 1) throw new OutOfMemoryException(CoreStrings.ObjectPool_GetAsync_Queue_Long(Policy.Name, Policy.AsyncGetCapacity)); @@ -412,6 +378,7 @@ namespace FreeSql.Internal.ObjectPool obj.LastGetThreadId = Thread.CurrentThread.ManagedThreadId; obj.LastGetTime = DateTime.Now; + obj.LastGetTimeCopy = DateTime.Now; Interlocked.Increment(ref obj._getTimes); return obj; @@ -420,40 +387,31 @@ namespace FreeSql.Internal.ObjectPool public void Return(Object obj, bool isReset = false) { - if (obj == null) return; - if (obj._isReturned) return; if (running == false) { - Policy.OnDestroy(obj.Value); try { (obj.Value as IDisposable)?.Dispose(); } catch { } - return; } if (isReset) obj.ResetValue(); - bool isReturn = false; while (isReturn == false && _getQueue.TryDequeue(out var isAsync)) { - if (isAsync == false) { - if (_getSyncQueue.TryDequeue(out var queueItem) && queueItem != null) { - lock (queueItem.Lock) if (queueItem.IsTimeout == false) queueItem.ReturnValue = obj; if (queueItem.ReturnValue != null) { - obj.LastReturnThreadId = Thread.CurrentThread.ManagedThreadId; obj.LastReturnTime = DateTime.Now; @@ -469,14 +427,11 @@ namespace FreeSql.Internal.ObjectPool try { queueItem.Dispose(); } catch { } } - } else { - if (_getAsyncQueue.TryDequeue(out var tcs) && tcs != null && tcs.Task.IsCanceled == false) { - obj.LastReturnThreadId = Thread.CurrentThread.ManagedThreadId; obj.LastReturnTime = DateTime.Now; @@ -509,11 +464,9 @@ namespace FreeSql.Internal.ObjectPool public void Dispose() { - running = false; while (_freeObjects.TryPop(out var fo)) ; - while (_getSyncQueue.TryDequeue(out var sync)) { try { sync.Wait.Set(); } catch { } @@ -535,13 +488,9 @@ namespace FreeSql.Internal.ObjectPool class GetSyncQueueInfo : IDisposable { - internal ManualResetEventSlim Wait { get; set; } = new ManualResetEventSlim(); - internal Object ReturnValue { get; set; } - internal object Lock = new object(); - internal bool IsTimeout { get; set; } = false; public void Dispose() diff --git a/Providers/FreeSql.Provider.ClickHouse/ClickHouseAdo/ClickHouseConnectionPool.cs b/Providers/FreeSql.Provider.ClickHouse/ClickHouseAdo/ClickHouseConnectionPool.cs index 1cc335ea..12416f36 100644 --- a/Providers/FreeSql.Provider.ClickHouse/ClickHouseAdo/ClickHouseConnectionPool.cs +++ b/Providers/FreeSql.Provider.ClickHouse/ClickHouseAdo/ClickHouseConnectionPool.cs @@ -34,7 +34,8 @@ namespace FreeSql.ClickHouse { if (exception != null && exception is ClickHouseException) { - try { if (obj.Value.Ping() == false) obj.Value.Open(); } catch { base.SetUnavailable(exception); } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -63,7 +64,7 @@ namespace FreeSql.ClickHouse public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -139,9 +140,8 @@ namespace FreeSql.ClickHouse { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -153,8 +153,9 @@ namespace FreeSql.ClickHouse } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -169,9 +170,8 @@ namespace FreeSql.ClickHouse { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -183,8 +183,9 @@ namespace FreeSql.ClickHouse } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Dameng/DamengAdo/DamengConnectionPool.cs b/Providers/FreeSql.Provider.Dameng/DamengAdo/DamengConnectionPool.cs index 709d0875..2c43d3f8 100644 --- a/Providers/FreeSql.Provider.Dameng/DamengAdo/DamengConnectionPool.cs +++ b/Providers/FreeSql.Provider.Dameng/DamengAdo/DamengConnectionPool.cs @@ -43,14 +43,8 @@ namespace FreeSql.Dameng { if (exception != null && exception is DmException) { - if (exception is System.IO.IOException) - { - base.SetUnavailable(exception); - } - else if (obj.Value.Ping() == false) - { - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -67,7 +61,7 @@ namespace FreeSql.Dameng public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -135,9 +129,8 @@ namespace FreeSql.Dameng { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -149,8 +142,9 @@ namespace FreeSql.Dameng } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -165,9 +159,8 @@ namespace FreeSql.Dameng { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -179,8 +172,9 @@ namespace FreeSql.Dameng } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Firebird/FirebirdAdo/FirebirdConnectionPool.cs b/Providers/FreeSql.Provider.Firebird/FirebirdAdo/FirebirdConnectionPool.cs index afb4c3cc..e82713c1 100644 --- a/Providers/FreeSql.Provider.Firebird/FirebirdAdo/FirebirdConnectionPool.cs +++ b/Providers/FreeSql.Provider.Firebird/FirebirdAdo/FirebirdConnectionPool.cs @@ -34,7 +34,8 @@ namespace FreeSql.Firebird { if (exception != null && exception is FbException) { - try { if (obj.Value.Ping() == false) obj.Value.Open(); } catch { base.SetUnavailable(exception); } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -51,7 +52,7 @@ namespace FreeSql.Firebird public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -119,9 +120,8 @@ namespace FreeSql.Firebird { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -133,8 +133,9 @@ namespace FreeSql.Firebird } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -149,9 +150,8 @@ namespace FreeSql.Firebird { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -163,8 +163,9 @@ namespace FreeSql.Firebird } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.GBase/GBaseAdo/GBaseConnectionPool.cs b/Providers/FreeSql.Provider.GBase/GBaseAdo/GBaseConnectionPool.cs index 5f61046e..095b8fe2 100644 --- a/Providers/FreeSql.Provider.GBase/GBaseAdo/GBaseConnectionPool.cs +++ b/Providers/FreeSql.Provider.GBase/GBaseAdo/GBaseConnectionPool.cs @@ -34,7 +34,8 @@ namespace FreeSql.GBase { if (exception != null && exception is OdbcException) { - try { if (obj.Value.Ping() == false) obj.Value.Open(); } catch { base.SetUnavailable(exception); } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -51,7 +52,7 @@ namespace FreeSql.GBase public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -118,9 +119,8 @@ namespace FreeSql.GBase { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -132,8 +132,9 @@ namespace FreeSql.GBase } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -148,9 +149,8 @@ namespace FreeSql.GBase { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -162,8 +162,9 @@ namespace FreeSql.GBase } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.KingbaseES/KingbaseESAdo/KingbaseESConnectionPool.cs b/Providers/FreeSql.Provider.KingbaseES/KingbaseESAdo/KingbaseESConnectionPool.cs index 048119c9..3c9b846f 100644 --- a/Providers/FreeSql.Provider.KingbaseES/KingbaseESAdo/KingbaseESConnectionPool.cs +++ b/Providers/FreeSql.Provider.KingbaseES/KingbaseESAdo/KingbaseESConnectionPool.cs @@ -45,18 +45,8 @@ namespace FreeSql.KingbaseES { if (exception != null && exception is KdbndpException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -73,7 +63,7 @@ namespace FreeSql.KingbaseES public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -140,9 +130,8 @@ namespace FreeSql.KingbaseES { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -154,8 +143,9 @@ namespace FreeSql.KingbaseES } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -170,9 +160,8 @@ namespace FreeSql.KingbaseES { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -184,8 +173,9 @@ namespace FreeSql.KingbaseES } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.MsAccess/MsAccessAdo/MsAccessConnectionPool.cs b/Providers/FreeSql.Provider.MsAccess/MsAccessAdo/MsAccessConnectionPool.cs index 7ccc7f1b..7283a015 100644 --- a/Providers/FreeSql.Provider.MsAccess/MsAccessAdo/MsAccessConnectionPool.cs +++ b/Providers/FreeSql.Provider.MsAccess/MsAccessAdo/MsAccessConnectionPool.cs @@ -34,12 +34,8 @@ namespace FreeSql.MsAccess { if (exception != null && exception is OleDbException) { - if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -56,7 +52,7 @@ namespace FreeSql.MsAccess public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; private string _connectionString; @@ -123,9 +119,8 @@ namespace FreeSql.MsAccess if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -137,8 +132,9 @@ namespace FreeSql.MsAccess } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -154,9 +150,8 @@ namespace FreeSql.MsAccess if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -168,8 +163,9 @@ namespace FreeSql.MsAccess } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.MySql/MySqlAdo/MySqlConnectionPool.cs b/Providers/FreeSql.Provider.MySql/MySqlAdo/MySqlConnectionPool.cs index ecde7d58..8bc611f0 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlAdo/MySqlConnectionPool.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlAdo/MySqlConnectionPool.cs @@ -38,7 +38,8 @@ namespace FreeSql.MySql { if (exception != null && exception is MySqlException) { - try { if (obj.Value.Ping() == false) obj.Value.Open(); } catch { base.SetUnavailable(exception); } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -55,7 +56,7 @@ namespace FreeSql.MySql public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -123,9 +124,8 @@ namespace FreeSql.MySql { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -137,8 +137,9 @@ namespace FreeSql.MySql } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -153,9 +154,8 @@ namespace FreeSql.MySql { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -167,8 +167,9 @@ namespace FreeSql.MySql } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs index d0570fed..359997b9 100644 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs +++ b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs @@ -45,18 +45,8 @@ namespace FreeSql.Odbc.Dameng { if (exception != null && exception is OdbcException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -73,7 +63,7 @@ namespace FreeSql.Odbc.Dameng public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -140,9 +130,8 @@ namespace FreeSql.Odbc.Dameng { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -154,8 +143,9 @@ namespace FreeSql.Odbc.Dameng } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -170,9 +160,8 @@ namespace FreeSql.Odbc.Dameng { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -184,8 +173,9 @@ namespace FreeSql.Odbc.Dameng } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcConnectionPool.cs index 86094ee0..d181b087 100644 --- a/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcConnectionPool.cs +++ b/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcConnectionPool.cs @@ -34,12 +34,8 @@ namespace FreeSql.Odbc.Default { if (exception != null && exception is OdbcException) { - if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -56,7 +52,7 @@ namespace FreeSql.Odbc.Default public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -124,9 +120,8 @@ namespace FreeSql.Odbc.Default if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -138,8 +133,9 @@ namespace FreeSql.Odbc.Default } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -155,9 +151,8 @@ namespace FreeSql.Odbc.Default if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -169,8 +164,9 @@ namespace FreeSql.Odbc.Default } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs index f9e989ff..b8ed480e 100644 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs +++ b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs @@ -45,18 +45,8 @@ namespace FreeSql.Odbc.KingbaseES { if (exception != null && exception is OdbcException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -73,7 +63,7 @@ namespace FreeSql.Odbc.KingbaseES public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -140,9 +130,8 @@ namespace FreeSql.Odbc.KingbaseES { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -154,8 +143,9 @@ namespace FreeSql.Odbc.KingbaseES } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -170,9 +160,8 @@ namespace FreeSql.Odbc.KingbaseES { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -184,8 +173,9 @@ namespace FreeSql.Odbc.KingbaseES } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlConnectionPool.cs index e1b4ce1b..114c6b44 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlConnectionPool.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlConnectionPool.cs @@ -34,7 +34,8 @@ namespace FreeSql.Odbc.MySql { if (exception != null && exception is OdbcException) { - try { if (obj.Value.Ping() == false) obj.Value.Open(); } catch { base.SetUnavailable(exception); } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -51,7 +52,7 @@ namespace FreeSql.Odbc.MySql public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -118,9 +119,8 @@ namespace FreeSql.Odbc.MySql { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -132,8 +132,9 @@ namespace FreeSql.Odbc.MySql } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -148,9 +149,8 @@ namespace FreeSql.Odbc.MySql { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -162,8 +162,9 @@ namespace FreeSql.Odbc.MySql } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleConnectionPool.cs index 7505b033..bd0a75f9 100644 --- a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleConnectionPool.cs +++ b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleConnectionPool.cs @@ -45,18 +45,8 @@ namespace FreeSql.Odbc.Oracle { if (exception != null && exception is OdbcException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -73,7 +63,7 @@ namespace FreeSql.Odbc.Oracle public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -140,9 +130,8 @@ namespace FreeSql.Odbc.Oracle { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -154,8 +143,9 @@ namespace FreeSql.Odbc.Oracle } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -170,9 +160,8 @@ namespace FreeSql.Odbc.Oracle { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -184,8 +173,9 @@ namespace FreeSql.Odbc.Oracle } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLConnectionPool.cs index 638fe5b3..23921daa 100644 --- a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLConnectionPool.cs +++ b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLConnectionPool.cs @@ -35,18 +35,8 @@ namespace FreeSql.Odbc.PostgreSQL { if (exception != null && exception is OdbcException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -63,7 +53,7 @@ namespace FreeSql.Odbc.PostgreSQL public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -130,9 +120,8 @@ namespace FreeSql.Odbc.PostgreSQL { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -144,8 +133,9 @@ namespace FreeSql.Odbc.PostgreSQL } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -160,9 +150,8 @@ namespace FreeSql.Odbc.PostgreSQL { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -174,8 +163,9 @@ namespace FreeSql.Odbc.PostgreSQL } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerConnectionPool.cs index 745b924c..537b7703 100644 --- a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerConnectionPool.cs +++ b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerConnectionPool.cs @@ -34,12 +34,8 @@ namespace FreeSql.Odbc.SqlServer { if (exception != null && exception is OdbcException) { - if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -56,7 +52,7 @@ namespace FreeSql.Odbc.SqlServer public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -124,9 +120,8 @@ namespace FreeSql.Odbc.SqlServer if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -138,8 +133,9 @@ namespace FreeSql.Odbc.SqlServer } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -155,9 +151,8 @@ namespace FreeSql.Odbc.SqlServer if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -169,8 +164,9 @@ namespace FreeSql.Odbc.SqlServer } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Oracle/OracleAdo/OracleConnectionPool.cs b/Providers/FreeSql.Provider.Oracle/OracleAdo/OracleConnectionPool.cs index 68865e20..46e112a9 100644 --- a/Providers/FreeSql.Provider.Oracle/OracleAdo/OracleConnectionPool.cs +++ b/Providers/FreeSql.Provider.Oracle/OracleAdo/OracleConnectionPool.cs @@ -45,18 +45,8 @@ namespace FreeSql.Oracle { if (exception != null && exception is OracleException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -73,7 +63,7 @@ namespace FreeSql.Oracle public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -141,9 +131,8 @@ namespace FreeSql.Oracle { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -155,8 +144,9 @@ namespace FreeSql.Oracle } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -171,9 +161,8 @@ namespace FreeSql.Oracle { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -185,8 +174,9 @@ namespace FreeSql.Oracle } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs index 2708ac47..dcd27704 100644 --- a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs +++ b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs @@ -35,18 +35,8 @@ namespace FreeSql.PostgreSQL { if (exception != null && exception is NpgsqlException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -63,7 +53,7 @@ namespace FreeSql.PostgreSQL public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -131,9 +121,8 @@ namespace FreeSql.PostgreSQL { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -145,8 +134,9 @@ namespace FreeSql.PostgreSQL } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -161,9 +151,8 @@ namespace FreeSql.PostgreSQL { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -175,8 +164,9 @@ namespace FreeSql.PostgreSQL } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.ShenTong/ShenTongAdo/ShenTongConnectionPool.cs b/Providers/FreeSql.Provider.ShenTong/ShenTongAdo/ShenTongConnectionPool.cs index cc63202a..f0ec4320 100644 --- a/Providers/FreeSql.Provider.ShenTong/ShenTongAdo/ShenTongConnectionPool.cs +++ b/Providers/FreeSql.Provider.ShenTong/ShenTongAdo/ShenTongConnectionPool.cs @@ -33,18 +33,8 @@ namespace FreeSql.ShenTong { if (exception != null && exception is OscarException) { - - if (exception is System.IO.IOException) - { - - base.SetUnavailable(exception); - - } - else if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -61,7 +51,7 @@ namespace FreeSql.ShenTong public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -129,9 +119,8 @@ namespace FreeSql.ShenTong { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -143,8 +132,9 @@ namespace FreeSql.ShenTong } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -159,9 +149,8 @@ namespace FreeSql.ShenTong { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -173,8 +162,9 @@ namespace FreeSql.ShenTong } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.SqlServer/SqlServerAdo/SqlServerConnectionPool.cs b/Providers/FreeSql.Provider.SqlServer/SqlServerAdo/SqlServerConnectionPool.cs index 922d9ee9..2a0a0edf 100644 --- a/Providers/FreeSql.Provider.SqlServer/SqlServerAdo/SqlServerConnectionPool.cs +++ b/Providers/FreeSql.Provider.SqlServer/SqlServerAdo/SqlServerConnectionPool.cs @@ -38,12 +38,8 @@ namespace FreeSql.SqlServer { if (exception != null && exception is SqlException) { - if (obj.Value.Ping() == false) - { - - base.SetUnavailable(exception); - } + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -60,7 +56,7 @@ namespace FreeSql.SqlServer public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); @@ -129,9 +125,8 @@ namespace FreeSql.SqlServer if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -143,8 +138,9 @@ namespace FreeSql.SqlServer } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -159,9 +155,8 @@ namespace FreeSql.SqlServer if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -173,8 +168,9 @@ namespace FreeSql.SqlServer } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs b/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs index f5677b1a..ce7e0af6 100644 --- a/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs +++ b/Providers/FreeSql.Provider.Sqlite/SqliteAdo/SqliteConnectionPool.cs @@ -44,7 +44,8 @@ namespace FreeSql.Sqlite if (exception != null && exception is SQLiteException) #endif { - try { if (obj.Value.Ping() == false) obj.Value.OpenAndAttach(policy.Attaches); } catch { base.SetUnavailable(exception); } + if (obj.Value.Ping() == false) + base.SetUnavailable(exception, obj.LastGetTimeCopy); } base.Return(obj, isRecreate); } @@ -63,7 +64,7 @@ namespace FreeSql.Sqlite public int AsyncGetCapacity { get; set; } = 10000; public bool IsThrowGetTimeoutException { get; set; } = true; public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 5; + public int CheckAvailableInterval { get; set; } = 2; public int Weight { get; set; } = 1; public string[] Attaches = new string[0]; @@ -158,9 +159,8 @@ namespace FreeSql.Sqlite { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误,或者检查项目属性 > 生成 > 目标平台:x86 | x64")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。或者检查项目属性 > 生成 > 目标平台:x86 | x64"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) @@ -172,8 +172,9 @@ namespace FreeSql.Sqlite } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } } @@ -188,9 +189,8 @@ namespace FreeSql.Sqlite { if (obj.Value == null) { - if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true) - throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); - return; + _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy); + throw new Exception($"【{this.Name}】连接字符串错误,请检查。"); } if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) @@ -202,8 +202,9 @@ namespace FreeSql.Sqlite } catch (Exception ex) { - if (_pool.SetUnavailable(ex) == true) + if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); + throw ex; } } }