1. 程式人生 > >【資料庫-MySql】 MySqlConnection error connecting: Timeout expired. (1)

【資料庫-MySql】 MySqlConnection error connecting: Timeout expired. (1)

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 資料庫名稱