title: Error max pool size was reached?
body: <p>I think this is because im not closing conections to my DB. I posted code im using below for my Datalayer. Do i need to close my conection? How would i do it too? Is this the code causing problems?</p>
  
  <p>Heres the error code:</p>
  
  <p>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. </p>
  
  <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.InvalidOperationException: 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.</p>
  
  <pre><code>public DataTable getPictures()
      {
  
          //get database connection string from config file
          string strConectionString = ConfigurationManager.AppSettings["DataBaseConnection"];
  
          //set up sql
          string StrSql = "SELECT MEMBERS.MemberName, Picture.PicLoc, Picture.PicID, Picture.PicRating FROM Picture INNER JOIN MEMBERS ON Picture.MemberID = MEMBERS.MemberID WHERE (Picture.PicID = @n) AND (Picture.PicAproval = 1) AND (Picture.PicArchive = 0)AND (MEMBERS.MemberSex = 'F')";
  
          DataTable dt = new DataTable();
          using (SqlDataAdapter daObj = new SqlDataAdapter(StrSql, strConectionString))
          {
              daObj.SelectCommand.Parameters.Add("@n", SqlDbType.Int);
              daObj.SelectCommand.Parameters["@n"].Value = GetItemFromArray();
  
              //fill data table
              daObj.Fill(dt);
          }
          return dt;
      }
  
  public int GetItemFromArray()
      {
          int myRandomPictureID;
          int[] pictureIDs = new int[GetTotalNumberOfAprovedPictureIds()];
  
  
          Random r = new Random();
          int MYrandom = r.Next(0, pictureIDs.Length);
  
          DLPicture GetPictureIds = new DLPicture();
          DataTable DAallAprovedPictureIds = GetPictureIds.GetPictureIdsIntoArray();
  
          //Assign Location and Rating to variables
          int i = 0;
          foreach (DataRow row in DAallAprovedPictureIds.Rows)
          {
  
              pictureIDs[i] = (int)row["PicID"];
              i++;
          }
  
          myRandomPictureID = pictureIDs[MYrandom];
          return myRandomPictureID;
      }
  
   public DataTable GetPictureIdsIntoArray()
      {
          string strConectionString = ConfigurationManager.AppSettings["DataBaseConnection"];
  
          //set up sql
          string StrSql = " SELECT Picture.PicID FROM MEMBERS INNER JOIN Picture ON MEMBERS.MemberID = Picture.MemberID WHERE (Picture.PicAproval = 1) AND (Picture.PicArchive = 0) AND (MEMBERS.MemberSex ='F')";
          DataTable dt = new DataTable();
          using (SqlDataAdapter daObj = new SqlDataAdapter(StrSql, strConectionString))
          {
  
              //fill data table
              daObj.Fill(dt);
          }
          return dt;
  
      }
  </code></pre>