接口运行一段时间后总是会报异常从连接池中获取连接异常 怎么解决? 返回

SqlSugar 待处理
274

数据库:sqlserver 2022 linux 免费版 用docker跑的

接口运行 1 到 2 天之后查询数据库就会提示:

SqlSugar.SqlSugarException: English Message : Connection open error . Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.

Chinese Message :  连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确,实在找不到原因请先Google错误信息:Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached..


重启接口容器之后正常,我是用 IOC 瞬发模式注册的 sqlsugarclient 示例,也开启了 IsAutoCloseConnection 按正常来说,这个接口也没有什么特别耗时的操作,只是查询数据库组装数据而已,而且并发也不是太高,都是一些 IOT 设备定时请求获取相关参数的接口,这个参数很少会更新,平时基本都在100ms 左右就返回,数据库连接字符串里面也手动开启了连接池,

Pooling=true;Max Pool Size=300;Min Pool Size=20;

sqlsugar 版本是:5.0.2.8

接口版本是:.net core 3.1

IOC 注册代码如下:

image.png

热忱回答0