title: Is using a singleton for the connection a good idea in ASP.NET website
body: <p>I'm currently using a singleton on my web application so that there is always only one connection to the database.</p>
  
  <p>I want to know if it's a good idea because right now I'm having trouble with that error:</p>
  
  <p><strong>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.</strong> </p>
  
  <p>Another important point is that my website is currently in dev and not a lot of people go on it so I don't understand why I get this error!</p>
  
  <p>Here is the code of my singleton:</p>
  
  <pre><code>using System;
  using System.Data;
  using System.Configuration;
  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.Data.SqlClient;
  
  /// &lt;summary&gt;
  /// This class take care of all the interaction with the database
  /// &lt;/summary&gt;
  public class DatabaseFacade
  {
      SqlConnection m_conn = null;
  
      string m_csLanguageColumn;
  
      //Variables that implement the Singleton pattern
      //Singleton pattern create only one instance of the class
      static DatabaseFacade instance = null;
      static readonly object padlock = new object();
  
      /// &lt;summary&gt;
      /// Private constructor. We must use Instance to use this class
      /// &lt;/summary&gt;
      private DatabaseFacade()
      {
      }
  
      /// &lt;summary&gt;
      /// Static method to implement the Singleton
      /// &lt;/summary&gt;
      public static DatabaseFacade Instance
      {
          get
          {
              lock (padlock)
              {
                  if (instance == null)
                  {
                      instance = new DatabaseFacade();
                  }
                  return instance;
              }
          }
      }
  
      /// &lt;summary&gt;
      /// Do the connection to the database
      /// &lt;/summary&gt;
      public void InitConnection(int nLanguage)
      {
          m_conn = new SqlConnection(GetGoodConnectionString());
  
          try
          {
              //We check if the connection is not already open
              if (m_conn.State != ConnectionState.Open)
              {
                  m_conn.Open();
              }
  
              m_csLanguageColumn = Tools.GetTranslationColumn(nLanguage);
  
          }
          catch (Exception err)
          {
              throw err;
          }
      }
  }
  </code></pre>
  
  <p>Thanks for your help!</p>