error connecting: Timeout expired.错误原因

error connecting: 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.

连接错误:超时过期,从连接池获取一个连接时超时,导致这个问题出现的原因有可能是连接池的所有连接都在使用且连接池的连接数已经达到最大。


解决方案:

1、如果是操作同一个数据库,建议只创建一次MySqlConnection且open一次,其他操作都调用这一个连接

 new MySqlConnection(connString);
 MySqlConnection.Open();

2、如果是操作不同的数据库,建议设置连接池的大小,建议单次调用时创建MySqlConnection的次数不要超过max pool size

           MySqlConnection.ConnectionString=   "server=192.1.33.26;port=8080;User Id=Admin;password=123456;pooling=true;min pool size=5;max pool size=1024;connect timeout = 20;database=Mydatabase;

1、server机器ip地址

2、port端口

3、User Id 用户名

4、password密码

5、pooling连接池

true 使用连接池

false不使用连接池

6、min pool size 连接池的容量下限

7、max pool size 连接池的容量上限 (注释容量越大耗时越多)

8、connect timeout 连接超时报警时间

9、database 数据库名称

标签

发表评论

评论列表(5)