Timeout expired. The timeout period elapsed prior to obtaining a connection from the

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bootsy
    New Member
    • Nov 2008
    • 4

    Timeout expired. The timeout period elapsed prior to obtaining a connection from the

    I get a timeout error using the code below. The Utils.GetDataTa bleForUI is calling a stored procedure(dbo.C onferencesSEL. The stored procedure does a simple select statement. Can someone tell me what I need to do to eliminate the timeout error on the page. Here is the code.

    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;
    
    namespace HSI
    {
        public partial class ofinterest_conferences : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                LoadConferences();
            }
    
            private void LoadConferences()
            {
                StringBuilder sb = new StringBuilder();
                DataTable dt = Utils.GetDataTableForUI("dbo.ConferencesSEL", null);
                
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append("<div class=\"infoContainer\">");
                    sb.Append("   <p>");
                    sb.Append("      <strong>" + dr["event_date"].ToString() +" : " + dr["title"].ToString() + " </strong><br />");
                    sb.Append("      " + dr["location"].ToString());
                    sb.Append("   </p>");
                    sb.Append("   <p class=\"moreInfoWrap\">");
    
                    string urlPDF = string.Empty;
                    if (!String.IsNullOrEmpty(dr["pdf_path"].ToString()))
                    {
                        urlPDF = (string)ConfigurationManager.AppSettings["pdfUploadPath"].ToString() + dr["pdf_path"].ToString();
                    }
                    else if (!String.IsNullOrEmpty(dr["url"].ToString()))
                    {
                        urlPDF = dr["url"].ToString();
                    }
    
    	            sb.Append("      <a href=\"" + urlPDF + "\" target=\"_blank\" class=\"moreInfo\">WANT MORE INFO</a>");
                    sb.Append("   </p>");
                    sb.Append("</div>");
                }
    
                this.confContainer.InnerHtml = sb.ToString();
            }
        }
    }
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well your error message is cutoff in the title of your post (please remember to put the error message in the body of your post as well)

    But it looks like it is timing out trying to connect to your database.
    Check your connection string and verify that your program has the correct credentials/permissions to connect to the database, and that it is not blocked by any firewalls or anything

    Comment

    • bootsy
      New Member
      • Nov 2008
      • 4

      #3
      Here it is:

      Code:
      using System;
      using System.Collections.Generic;
      using System.Data;
      using System.Data.SqlClient;
      using System.Web.UI;
      namespace HSI 
      {
        public class Utils : Page
        {
          public Utils();
      Last edited by Curtis Rutland; Nov 13 '08, 05:49 PM. Reason: added [CODE] tags.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        What is that ?

        Comment

        • bootsy
          New Member
          • Nov 2008
          • 4

          #5
          Originally posted by Plater
          What is that ?
          That's the connection string to the Utils functiion

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Originally posted by bootsy
            That's the connection string to the Utils functiion
            There is no connection string in that code. All you posted was your using statements

            Comment

            • bootsy
              New Member
              • Nov 2008
              • 4

              #7
              Originally posted by Plater
              There is no connection string in that code. All you posted was your using statements
              Sorry I forgot to post the rest of the code



              Also this:

              Code:
              public static DataTable GetDataTableForUI(string sproc, List<SqlParameter> sps) 
              {
              
              SqlConnection conn = new SqlConnection((string)ConfigurationSettings.AppSettings["DBConnectionString"]); 
              conn.Open();
              
              SqlCommand comm = new SqlCommand(sproc, conn); 
              comm.CommandType = CommandType.StoredProcedure;
              
              if (sps != null) 
              {
              
              for (int i = 0; i < sps.Count; i++) 
              {
              
              comm.Parameters.Add(sps[i]);
              
              }
              
              }
              
              SqlDataAdapter da = new SqlDataAdapter(comm);DataTable dt = new DataTable(); 
              da.Fill(dt);
              
              return dt;
              
              }

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Well that still doesn't include your connection string, because its referencing one stored in your web.config file.

                Comment

                Working...