- 优化 连接池不可用、定时检查;

This commit is contained in:
2881099 2022-05-28 22:09:45 +08:00
parent 67b4e8fbe1
commit 4c7de1da8a
25 changed files with 222 additions and 372 deletions

View File

@ -4331,7 +4331,7 @@
不可用时间
</summary>
</member>
<member name="M:FreeSql.Internal.ObjectPool.IObjectPool`1.SetUnavailable(System.Exception)">
<member name="M:FreeSql.Internal.ObjectPool.IObjectPool`1.SetUnavailable(System.Exception,System.DateTime)">
<summary>
将对象池设置为不可用,后续 Get/GetAsync 均会报错,同时启动后台定时检查服务恢复可用
</summary>

View File

@ -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()

View File

@ -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<T> CreateObject;

View File

@ -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 均会报错,同时启动后台定时检查服务恢复可用
/// </summary>
/// <param name="exception"></param>
/// <param name="lastGetTime"></param>
/// <returns>由【可用】变成【不可用】时返回true否则返回false</returns>
bool SetUnavailable(Exception exception);
bool SetUnavailable(Exception exception, DateTime lastGetTime);
/// <summary>
/// 统计对象池中的对象

View File

@ -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; }
/// <summary>
/// 最后归还时的时间

View File

@ -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
/// <param name="interval"></param>
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<T> { Pool = this, Id = _allObjects.Count + 1 });
@ -310,12 +283,9 @@ namespace FreeSql.Internal.ObjectPool
public Object<T> 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<Object<T>> 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<T> 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<T> ReturnValue { get; set; }
internal object Lock = new object();
internal bool IsTimeout { get; set; } = false;
public void Dispose()

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -139,9 +140,8 @@ namespace FreeSql.ClickHouse
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -135,9 +129,8 @@ namespace FreeSql.Dameng
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -119,9 +120,8 @@ namespace FreeSql.Firebird
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -118,9 +119,8 @@ namespace FreeSql.GBase
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -140,9 +130,8 @@ namespace FreeSql.KingbaseES
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -123,9 +124,8 @@ namespace FreeSql.MySql
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -140,9 +130,8 @@ namespace FreeSql.Odbc.Dameng
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -124,9 +120,8 @@ namespace FreeSql.Odbc.Default
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -140,9 +130,8 @@ namespace FreeSql.Odbc.KingbaseES
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -118,9 +119,8 @@ namespace FreeSql.Odbc.MySql
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -140,9 +130,8 @@ namespace FreeSql.Odbc.Oracle
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -130,9 +120,8 @@ namespace FreeSql.Odbc.PostgreSQL
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -124,9 +120,8 @@ namespace FreeSql.Odbc.SqlServer
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -141,9 +131,8 @@ namespace FreeSql.Oracle
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -131,9 +121,8 @@ namespace FreeSql.PostgreSQL
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -129,9 +119,8 @@ namespace FreeSql.ShenTong
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
@ -129,9 +125,8 @@ namespace FreeSql.SqlServer
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}

View File

@ -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)
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
return;
}
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;
}
}
}