Cấp bậc tác giả:

DOTNET

Fix lỗi Max pool size was reached

Được viết bởi QuangIT ngày 21/09/2012 lúc 10:12 PM
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.
  • 0
  • 13606

Fix lỗi Max pool size was reached

Thông báo lỗi:


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.


Lỗi trên có một số nguyên nhân dẫn đến như sau:

1. Số lượng kết nối MSSQL và thời gian kết nối MSSQL ngắn có thề tùy chình lại bằng cách vào "SQL Server Management Studio - Properties - Connections" điều chỉnh lại cho phù hợp.


2. Pool Size thấp để chỉnh cái này chúng ta có thể khai báo ở connectionString của mình ví dụ:


string MyConnectString = "Data Source=.\\SQLEXPRESS;Initial Catalog=huynhvanmot;Integrated Security=True;Max Pool Size=100;Min Pool Size=5";

Mặc định Max Pool Size hình như là 75 (không rõ) tùy site lớn nhỏ chỉnh cho phù hợp.


3. Lỗi thứ 3 hay gặp nhất là chúng ta kết nối MSSQL thông qua một lớp khác, mở quá nhiều kết nối mà không có đóng lại.

Mình share cho các bạn BDClass của mình các bạn tham khảo và góp ý thêm nhé


public static SqlConnection taoketnoi()

{

string chuoi = "Data Source=.\\SQLEXPRESS;Initial Catalog=huynhvanmot;Integrated Security=True;Max Pool Size=300;Min Pool Size=5";

SqlConnection con = new SqlConnection(chuoi);

con.Open();

return con;

}


public static DataTable TruyVan_TraVe_DataTable(string strSQL)

{

SqlConnection con = taoketnoi();

try

{

SqlDataAdapter da = new SqlDataAdapter(strSQL, con);

DataTable dt = new DataTable();

da.Fill(dt);

return dt;

}

finally

{

//'finally' block is ALWAYS get called.

con.Close();

con.Dispose();

}


}

Huy vọng giúp ít được cho mọi người !

Nguồn bài viết: Dngaz.com

BÌNH LUẬN BÀI VIẾT

Bài viết mới nhất

LIKE BOX

Bài viết được xem nhiều nhất

HỌC HTML