日期:2014-05-19  浏览次数:20739 次

急,访客增多,系统经常报错为:连接超时,如何解决?
报错如下:

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


在网上搜了一下,解释为连接过多,sqlconnection   打开后未关闭造成的!

下面是我的SQL访问代码,大家帮我看看有无关闭连接的问题?

如无问题,访客增多,如何增加连接池数量?谢谢!

public   sealed   class   sql
{


        private   sql()   {   }

        //Database   connection   strings
        public   static   readonly   string   CONN_STRING   =   ConfigurationManager.ConnectionStrings[ "space_wenxueConnectionString "].ConnectionString;

        ///   <summary>
        ///   Execute   a   SqlCommand   that   returns   a   resultset   against   the   database   specified   in   the   connection   string  
        ///   using   the   provided   parameters.
        ///   </summary>
        ///   <remarks>
        ///   e.g.:    
        ///     SqlDataReader   r   =   ExecuteReader(connString,   CommandType.StoredProcedure,   "PublishOrders ",   new   SqlParameter( "@prodid ",   24));
        ///   </remarks>
        ///   <param   name= "cmdType "> the   CommandType   (stored   procedure,   text,   etc.) </param>
        ///   <param   name= "cmdText "> the   stored   procedure   name   or   T-SQL   command </param>
        ///   <param   name= "cmdParms "> an   array   of   SqlParamters   used   to   execute   the   command </param>
        ///   <returns> A   SqlDataReader   containing   the   results </returns>
        public   static   SqlDataReader   ExecuteReader(CommandType   cmdType,   string   cmdText,   params   SqlParameter[]   cmdParms)
        {
                SqlCommand   cmd   =   new   SqlCommand();
                SqlConnection   conn   =   new   SqlConnection(CONN_STRING);

                //   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