Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Nov 2008
Posts: 4
#1: Nov 13 '08
I get a timeout error using the code below. The Utils.GetDataTableForUI is calling a stored procedure(dbo.ConferencesSEL. 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.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Text;
  12.  
  13. namespace HSI
  14. {
  15.     public partial class ofinterest_conferences : System.Web.UI.Page
  16.     {
  17.         protected void Page_Load(object sender, EventArgs e)
  18.         {
  19.             LoadConferences();
  20.         }
  21.  
  22.         private void LoadConferences()
  23.         {
  24.             StringBuilder sb = new StringBuilder();
  25.             DataTable dt = Utils.GetDataTableForUI("dbo.ConferencesSEL", null);
  26.  
  27.             foreach (DataRow dr in dt.Rows)
  28.             {
  29.                 sb.Append("<div class=\"infoContainer\">");
  30.                 sb.Append("   <p>");
  31.                 sb.Append("      <strong>" + dr["event_date"].ToString() +" : " + dr["title"].ToString() + " </strong><br />");
  32.                 sb.Append("      " + dr["location"].ToString());
  33.                 sb.Append("   </p>");
  34.                 sb.Append("   <p class=\"moreInfoWrap\">");
  35.  
  36.                 string urlPDF = string.Empty;
  37.                 if (!String.IsNullOrEmpty(dr["pdf_path"].ToString()))
  38.                 {
  39.                     urlPDF = (string)ConfigurationManager.AppSettings["pdfUploadPath"].ToString() + dr["pdf_path"].ToString();
  40.                 }
  41.                 else if (!String.IsNullOrEmpty(dr["url"].ToString()))
  42.                 {
  43.                     urlPDF = dr["url"].ToString();
  44.                 }
  45.  
  46.                 sb.Append("      <a href=\"" + urlPDF + "\" target=\"_blank\" class=\"moreInfo\">WANT MORE INFO</a>");
  47.                 sb.Append("   </p>");
  48.                 sb.Append("</div>");
  49.             }
  50.  
  51.             this.confContainer.InnerHtml = sb.ToString();
  52.         }
  53.     }
  54. }
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,158
#2: Nov 13 '08

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


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
Newbie
 
Join Date: Nov 2008
Posts: 4
#3: Nov 13 '08

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


Here it is:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Web.UI;
  6. namespace HSI 
  7. {
  8.   public class Utils : Page
  9.   {
  10.     public Utils();
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,158
#4: Nov 13 '08

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


What is that ?
Newbie
 
Join Date: Nov 2008
Posts: 4
#5: Nov 13 '08

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


Quote:

Originally Posted by Plater

What is that ?

That's the connection string to the Utils functiion
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,158
#6: Nov 13 '08

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


Quote:

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
Newbie
 
Join Date: Nov 2008
Posts: 4
#7: Nov 13 '08

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


Quote:

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:

Expand|Select|Wrap|Line Numbers
  1. public static DataTable GetDataTableForUI(string sproc, List<SqlParameter> sps) 
  2. {
  3.  
  4. SqlConnection conn = new SqlConnection((string)ConfigurationSettings.AppSettings["DBConnectionString"]); 
  5. conn.Open();
  6.  
  7. SqlCommand comm = new SqlCommand(sproc, conn); 
  8. comm.CommandType = CommandType.StoredProcedure;
  9.  
  10. if (sps != null) 
  11. {
  12.  
  13. for (int i = 0; i < sps.Count; i++) 
  14. {
  15.  
  16. comm.Parameters.Add(sps[i]);
  17.  
  18. }
  19.  
  20. }
  21.  
  22. SqlDataAdapter da = new SqlDataAdapter(comm);DataTable dt = new DataTable(); 
  23. da.Fill(dt);
  24.  
  25. return dt;
  26.  
  27. }
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,158
#8: Nov 13 '08

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


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