超时时间已到。为什么!有关问题在那里啊求详解!
超时时间已到。为什么!!!!问题在那里啊!!!!求详解!!!
超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
先看SqlHelper代码(我自己认为没有问题的)
这是Web.config 中配置
这是在数据操作类中的代码
为何,会出超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
先看SqlHelper代码(我自己认为没有问题的)
- SQL code
// //这个应该是没有问题的吧 // public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand cmd = new SqlCommand(); SqlConnection conn = new SqlConnection(connectionString); // we use a try/catch here because if the method throws an exception we want to // close the connection throw code, because no datareader will exist, hence the // commandBehaviour.CloseConnection will not work try { PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); cmd.Parameters.Clear(); return rdr; } catch { conn.Close(); throw; } }
- SQL code
/// <summary> /// Prepare a command for execution(数据访问层方法) /// </summary> /// <param name="cmd">SqlCommand object(SQL命令)</param> /// <param name="conn">SqlConnection object(连接对象)</param> /// <param name="trans">SqlTransaction object(事务)</param> /// <param name="cmdType">Cmd type e.g. stored procedure or text(键入cmd存储过程或文本)</param> /// <param name="cmdText">Command text, e.g. Select * from Causewares(SQL语句)</param> /// <param name="cmdParms">SqlParameters to use in the command(SQL语句参数)</param> private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) { //如果数据库没有打开的话,就打开 if (conn.State != ConnectionState.Open) conn.Open(); cmd.Connection = conn;//SQL命令中的链接对象就是传过来的连接对象(数据服务器,账号,密码) cmd.CommandText = cmdText;//SQL命令中的SQL语句就是传过来的SQL语句 //如果没有事务的话 if (trans != null) cmd.Transaction = trans;//SQL命令的事务就等于传过来的事务 cmd.CommandType = cmdType;//SQL命令的储存过程就等于传过来的储存过程 //如果SQL语句有参数的话 //遍历所有参数添加到SQL语句对应的参数地址 if (cmdParms != null) { foreach (SqlParameter parm in cmdParms) cmd.Parameters.Add(parm); } }
这是Web.config 中配置
- C# code
<connectionStrings> <add name="SQLConnString4" connectionString="server=192.168.0.0;uid=sa;pwd=pwd;database=neware200907;" providerName="System.Data.SqlClient"/ > //难道要在这里加参数,,, <add name="SQLProfileConnString" connectionString=""/> </connectionStrings>
这是在数据操作类中的代码
- C# code
using (IDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransactionSAP, CommandType.Text, strSql)) { List<OSLPEntity> list = new List<OSLPEntity>(); while (dr.Read()) { list.Add(newSQLOSLPEntity(dr)); } return list; } // //这里使用using()没有问题吧, //
为何,会出超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。