唉,最后一步了! C# winform程序在公司测试没有任何问题,到客户现场安装老是弹出一个错误提示"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.",网上说是数据库连接没关闭,可是我组查了代码,每一个连接数据库的类中都关闭了数据库连接,都用了 using (SqlConnection con = SqlHelper.GetConnection()) try { con.Open(); string cmdSelect = "select room_id,bed_Name,sickName,sex,NurLevel,illState,Cared,Wcfs from BASE_BED where hushisiteID='" + Init.GetHushisiteIdByIp() + "'order by room_id,bed_Name"; using (SqlCommand cmd = new SqlCommand(cmdSelect, con)) { using (SqlDataReader dr = cmd.ExecuteReader()) {.... .} } }这类语法,可是软件运行时间久了还是会出现上面的错误,请教各位高手。
------解决方案-------------------- 使用了DataReader,你即使离开Using语句块,连接还是被保持着,否则DataReader怎么读取数据?
------解决方案-------------------- (SqlDataReader dr = cmd.ExecuteReader()) 对 这里 少个参数 using (SqlDataReader readerTemp = cmdTemp.ExecuteReader(CommandBehavior.CloseConnection))
------解决方案-------------------- 最简单的办法:把所有的con.Open();换成下面这句
C# code
if (con.State==ConnectionState.Closed) con.Open();
------解决方案--------------------