Unanswered Too many connections opened.

  • Wednesday, April 13, 2011 1:40 AM
     
      Has Code
    how can I fix the below code so I don't get the following error:
    
     get a time out when I try to goto omegalove.com<br/>Server Error in '/' Application.<br/>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.<br/>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.<br/><br/>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.<br/><br/>Source Error:<br/><br/>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.<br/><br/>Stack Trace:<br/><br/>[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.]<br/>System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4863722<br/>System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117<br/>System.Data.SqlClient.SqlConnection.Open() +122<br/>Microsoft.Practices.EnterpriseLibrary.Data.Database.GetNewOpenConnection() +137<br/>Microsoft.Practices.EnterpriseLibrary.Data.Database.GetOpenConnection(Boolean disposeInnerConnection) +74<br/>Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteReader(DbCommand command) +41<br/>SQLOmegaLoveProvider.GetRandomPhotos() in C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs:2649<br/>OmegaLoveHelper.GetRandomPhotos() in C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\OmegaLove\OmegaLoveHelper.cs:154<br/>OmegaLove.Web.UI.ctrlRandomMembers.DisplayImagesRandom() in C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Controls\ctrlRandomMembers.ascx.cs:28<br/>OmegaLove.Web.UI.ctrlRandomMembers.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Controls\ctrlRandomMembers.ascx.cs:23<br/>System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14<br/>System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35<br/>System.Web.UI.Control.OnLoad(EventArgs e) +99<br/>System.Web.UI.Control.LoadRecursive() +50<br/>System.Web.UI.Control.LoadRecursive() +141<br/>System.Web.UI.Control.LoadRecursive() +141<br/>System.Web.UI.Control.LoadRecursive() +141<br/>System.Web.UI.Control.LoadRecursive() +141<br/>System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627<br/><br/><br/>Version Information: Microsoft .NET Framework Version:2.0.50727.3615; ASP.NET Version:2.0.50727.3618 <br/><br/>----------------------------<br/>IP Address: 24.76.239.26
    
    public static DBPhotosCollection GetRandomPhotos()
      {
        DBPhotosCollection photosCollection = new DBPhotosCollection();
        Database db = OmegaLoveSqlDataHelper.CreateConnection(ConnnectionString);
        DbCommand dbCommand = db.GetStoredProcCommand("prc_Photos_Select_Random");
    
        using (IDataReader dataReader = db.ExecuteReader(dbCommand))
        {
          while (dataReader.Read())
          {
            DBPhotos photos = GetPhotosFromReader(dataReader);
            photosCollection.Add(photos);
          }
        }
    
    
        return photosCollection;
    
      }
    

    Mathieu Alexandre Cupryk www.omegalove.com

All Replies

  • Wednesday, April 13, 2011 4:28 AM
     
     

    Would you like to show me the connection string you have it?

    Maybe you can set the timeout time in the connection string, if its not in it, put it into it.


    Mitja
  • Wednesday, April 13, 2011 6:46 AM
     
     

    Whatever your problem is, 

    You can in your program only use one connection to a database at a time.

    (Or you should use the new features which can enable in a very difficult way more concurrent connections)


    Success
    Cor
  • Wednesday, April 13, 2011 10:15 PM
     
     

    I have on the first page of omegalove.com

    a banner of photos being called from a database.

     


    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 13, 2011 10:19 PM
     
     

    Each time a user goes to the page the routine is called.

    <

     

    add name="omegaloveConnectionString" connectionString="Data Source=72.18.146.251,1533;Initial Catalog=omegalove;Persist Security Info=True;User ID=omegalove;Password=;Connect Timeout=200" providerName="System.Data.SqlClient"

    />

     


    Mathieu Alexandre Cupryk www.omegalove.com
  • Thursday, April 14, 2011 2:46 AM
     
     
    .
  • Thursday, April 14, 2011 2:57 AM
     
      Has Code

    I don't do a lot of database stuff so maybe this is not worth the electrons used to put it on your screen.

    collapse db instead of dbCommand:

     public static DBPhotosCollection GetRandomPhotos()
     {
      DBPhotosCollection photosCollection = new DBPhotosCollection();
      
      
    
      using (Database db = OmegaLoveSqlDataHelper.CreateConnection(ConnnectionString))
      {
        DbCommand dbCommand = db.GetStoredProcCommand("prc_Photos_Select_Random");
        IDataReader dataReader = db.ExecuteReader(dbCommand)
       while (dataReader.Read())
       {
        DBPhotos photos = GetPhotosFromReader(dataReader);
        photosCollection.Add(photos);
       }
      }
    
    
      return photosCollection;
    
     }

  • Monday, April 18, 2011 12:23 PM
    Moderator
     
     

    Any update? Has your question been solved?

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Monday, April 18, 2011 1:03 PM
     
     

    Nope, this is not asnwered.


    Mathieu Alexandre Cupryk www.omegalove.com
  • Monday, April 18, 2011 2:42 PM
     
     

    Well,

    You're passing the reader that you're looping though...

    DBPhotos photos = GetPhotosFromReader(dataReader);

    You have to open another connection to the same reader. You might want to just pass the command object and execute the reader again BUT...why are you looping through a reader and making a call to function passing the reader begin with? That makes no sense.

    Adam


    Ctrl+Z
  • Monday, April 18, 2011 3:37 PM
     
     

    Ok, so what do you think I should do?


    Mathieu Alexandre Cupryk www.omegalove.com
  • Monday, April 18, 2011 4:00 PM
     
     

    Change the code to this...I think this is what you want anyway:

      using (Database db = OmegaLoveSqlDataHelper.CreateConnection(ConnnectionString))
      {
        DbCommand dbCommand = db.GetStoredProcCommand("prc_Photos_Select_Random");
        IDataReader dataReader = db.ExecuteReader(dbCommand)
       while (dataReader.Read())
       {
        DBPhotos photos = GetPhotosFromReader(dataReader[0].toString());
        photosCollection.Add(photos);
       }
      }


    Ctrl+Z
  • Monday, April 18, 2011 4:13 PM
     
     
    What does the GetPhotosFromReader method do?
  • Wednesday, April 20, 2011 1:42 AM
     
      Has Code
    Error	1	'Microsoft.Practices.EnterpriseLibrary.Data.Database': type used in a using statement must be implicitly convertible to 'System.IDisposable'	C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs	2674	9	OmegaLove.Web
    
    using (Database db = OmegaLoveSqlDataHelper.CreateConnection(ConnnectionString))
        {
           DbCommand dbCommand = db.GetStoredProcCommand("prc_Photos_Select_Random");
           IDataReader dataReader = db.ExecuteReader(dbCommand);
           while (dataReader.Read())
           {
             DBPhotos photos = GetPhotosFromReader(dataReader);
             photosCollection.Add(photos);
           }
        }
    
    private static DBPhotos GetPhotosFromReader(IDataReader dataReader)
      {
        DBPhotos photos = new DBPhotos();
    
        photos.PhotoID = OmegaLoveSqlDataHelper.GetInt(dataReader, "PhotoID");
        photos.p_UserName = OmegaLoveSqlDataHelper.GetString(dataReader, "p_UserName");
        photos.p_Image = OmegaLoveSqlDataHelper.GetBytes(dataReader, "p_Image");
        photos.p_Name = OmegaLoveSqlDataHelper.GetString(dataReader, "p_Name");
        photos.p_Description = OmegaLoveSqlDataHelper.GetString(dataReader, "p_Description");
        photos.p_Type = OmegaLoveSqlDataHelper.GetString(dataReader, "p_Type");
        photos.p_Size = OmegaLoveSqlDataHelper.GetLong(dataReader, "p_Size");
        photos.p_Approved = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Approved");
        photos.p_Primary = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Primary");
        photos.p_Explicit = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Explicit");
        photos.p_Private = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Private");
        photos.ProfileID = OmegaLoveSqlDataHelper.GetInt(dataReader, "ProfileID");
    
        return photos;
      }

    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 8:28 AM
     
     

    Where/when did you 'Closed' your connection to database? Thats the problem.

    In your snippet method code, I can't see where did you build your connection, because you've wrapped it to your own SqlHelper Class


    Regards, Christofel
  • Wednesday, April 20, 2011 1:03 PM
     
     
    Not sure where to close. The using statement should close the connect?
    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 1:55 PM
     
     

    You're still passing a open reader that you're looping through. You can't do that.

    Can you post the code the for the method GetPhotosFromReader()

    Adam


    Ctrl+Z
  • Wednesday, April 20, 2011 3:39 PM
     
      Has Code

    Hi Macupryk,

     

    OmegaLoveSqlDataHelper Here you are opening a connection. You need to have reference to the connection and OmegaLoveSqlDataHelper
    should have a method close connection. That close method needs to close the opened connection and to be called after you read the data.

    Also try to debug you code and get the specif line of code which throw the exception. That would help the problem solve easily. To know it is timeout
    problem or connection pool exhaust work with a small set of data but access it repeatedly. If it works first then after many repetition it throw error means
    a connection pool exhaust problem because of not closed connection. If it works with small set of data then try with a large set. If not working with large set then
    it would be a timeout issue, adjust with the time out property.

    good luck
  • Wednesday, April 20, 2011 4:11 PM
     
     
    i don't have a close connection method.
    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 4:17 PM
     
     

    Can you post the code the for the method GetPhotosFromReader()


    Ctrl+Z
  • Wednesday, April 20, 2011 4:54 PM
     
      Has Code
    private static DBPhotos GetPhotosFromReader(IDataReader dataReader)
     {
      DBPhotos photos = new DBPhotos();
    
      photos.PhotoID = OmegaLoveSqlDataHelper.GetInt(dataReader, "PhotoID");
      photos.p_UserName = OmegaLoveSqlDataHelper.GetString(dataReader, "p_UserName");
      photos.p_Image = OmegaLoveSqlDataHelper.GetBytes(dataReader, "p_Image");
      photos.p_Name = OmegaLoveSqlDataHelper.GetString(dataReader, "p_Name");
      photos.p_Description = OmegaLoveSqlDataHelper.GetString(dataReader, "p_Description");
      photos.p_Type = OmegaLoveSqlDataHelper.GetString(dataReader, "p_Type");
      photos.p_Size = OmegaLoveSqlDataHelper.GetLong(dataReader, "p_Size");
      photos.p_Approved = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Approved");
      photos.p_Primary = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Primary");
      photos.p_Explicit = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Explicit");
      photos.p_Private = OmegaLoveSqlDataHelper.GetBoolean(dataReader, "p_Private");
      photos.ProfileID = OmegaLoveSqlDataHelper.GetInt(dataReader, "ProfileID");
    
      return photos;
     }
    --------------------------------------------------------------------------------
    
    you can download nopcommerce 1.40
    they do the same thing. What am I missing.

    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 5:03 PM
     
     

    You're passing an open datareader 3 times?

    Aye, aye, aye, I give up sorry.

    Adam


    Ctrl+Z
  • Wednesday, April 20, 2011 5:29 PM
     
     
    what do you mean u give up. don't giveup.
    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 7:04 PM
     
     

    Ok I'll stick with you for a little while longer. Do you have access to the OmegaLoveSqlDataHelper class?

     


    Ctrl+Z
  • Wednesday, April 20, 2011 8:03 PM
     
      Has Code
     public partial class OmegaLoveSqlDataHelper
      {
        #region Methods
    
        internal static string GetConnectionString(string ConnectionStringName)
        {
          string connectionString = null;
    
          ConnectionStringSettings settings = WebConfigurationManager.ConnectionStrings[ConnectionStringName];
          if (settings != null)
          {
            connectionString = settings.ConnectionString;
          }
    
          return connectionString;
        }
    
        /// <summary>
        /// Creates a connection to a data soruce
        /// </summary>
        /// <param name="ConnectionString">Connection string</param>
        /// <returns>Database instance</returns>
        public static Database CreateConnection(string ConnectionString)
        {
          SqlDatabase db = new SqlDatabase(ConnectionString);
          return db;
        }
    
        /// <summary>
        /// Gets a boolean value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A boolean value</returns>
        public static bool GetBoolean(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return false;
          }
          return Convert.ToBoolean(rdr[index]);
        }
    
        /// <summary>
        /// Gets a byte array of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A byte array</returns>
        public static byte[] GetBytes(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return null;
          }
          return (byte[])rdr[index];
        }
    
        /// <summary>
        /// Gets a datetime value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A date time</returns>
        public static DateTime GetDateTime(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return DateTime.MinValue;
          }
          return (DateTime)rdr[index];
        }
    
        /// <summary>
        /// Gets an UTC datetime value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A date time</returns>
        public static DateTime GetUtcDateTime(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return DateTime.MinValue;
          }
          return DateTime.SpecifyKind((DateTime)rdr[index], DateTimeKind.Utc);
        }
    
        /// <summary>
        /// Gets a nullable datetime value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A date time if exists; otherwise, null</returns>
        public static DateTime? GetNullableDateTime(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return null;
          }
          return (DateTime)rdr[index];
        }
    
        /// <summary>
        /// Gets a nullable UTC datetime value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A date time if exists; otherwise, null</returns>
        public static DateTime? GetNullableUtcDateTime(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return null;
          }
          return DateTime.SpecifyKind((DateTime)rdr[index], DateTimeKind.Utc);
        }
    
        /// <summary>
        /// Gets a decimal value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A decimal value</returns>
        public static decimal GetDecimal(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return decimal.Zero;
          }
          return Convert.ToDecimal(rdr[index]);
        }
    
        /// <summary>
        /// Gets a double value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A double value</returns>
        public static double GetDouble(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return 0.0;
          }
          return (double)rdr[index];
        }
    
        /// <summary>
        /// Gets a GUID value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A GUID value</returns>
        public static Guid GetGuid(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return Guid.Empty;
          }
          return (Guid)rdr[index];
        }
    
        /// <summary>
        /// Gets an integer value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>An integer value</returns>
        public static int GetInt(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return 0;
          }
          return (int)rdr[index];
        }
    
        /// <summary>
        /// Gets a nullable integer value of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A nullable integer value</returns>
        public static int? GetNullableInt(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return null;
          }
          return (int)rdr[index];
        }
    
        /// <summary>
        /// Gets a string of a data reader by a column name
        /// </summary>
        /// <param name="rdr">Data reader</param>
        /// <param name="columnName">Column name</param>
        /// <returns>A string value</returns>
        public static string GetString(IDataReader rdr, string columnName)
        {
          int index = rdr.GetOrdinal(columnName);
          if (rdr.IsDBNull(index))
          {
            return string.Empty;
          }
          return (string)rdr[index];
        }
        #endregion
      }
    }
    

    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 9:01 PM
     
     

    There's the problem. That class is trying to create a new connection to an open datareader that already has an open connection.

    You have to close the connection in your loop before you make that call.

    Adam


    Ctrl+Z
  • Wednesday, April 20, 2011 9:33 PM
     
     
    where is dataReader.Close()
    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 10:02 PM
     
      Has Code

    Try this:

    using (Database db = OmegaLoveSqlDataHelper.CreateConnection(ConnnectionString))
    {
    DbCommand dbCommand = db.GetStoredProcCommand("prc_Photos_Select_Random");
    IDataReader dataReader = db.ExecuteReader(dbCommand);
    for each photos as dbphotos in GetPhotosFromReader(datareader)
    {
    photosCollection.Add(photos.Name);

    }
    }

    Ctrl+Z
  • Wednesday, April 20, 2011 10:37 PM
     
      Has Code
    using (Database db = OmegaLoveSqlDataHelper.CreateConnection(ConnnectionString)) 
        {  
          DbCommand dbCommand = db.GetStoredProcCommand("prc_Photos_Select_Random");  
          IDataReader dataReader = db.ExecuteReader(dbCommand);
          foreach ((DBPhotos photos) in (GetPhotosFromReader(dataReader))
          { 
            photosCollection.Add(photos);
          }
    
        }
    the foreach is not compiling
    Error 1 Type expected C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs 2678 21 OmegaLove.Web
    Error 5 Invalid expression term 'in' C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs 2678 39 OmegaLove.Web
    Error 3 Invalid expression term ')' C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs 2678 37 OmegaLove.Web
    Error 4 ; expected C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs 2678 37 OmegaLove.Web
    Error 6 ; expected C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs 2678 39 OmegaLove.Web
    Error 7 ; expected C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs 2678 75 OmegaLove.Web
    Error 2 ) expected C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs 2678 31 OmegaLove.Web

    Mathieu Alexandre Cupryk www.omegalove.com
  • Wednesday, April 20, 2011 11:50 PM
     
     

    The most likely culprits for those errors are a missing ";" or missing or extra "{" or "(" ")"

     

    foreach((DBPhotos photos) in (GetPhotosFromReader(dataReader)) looks strange and there is a missing ")" on the end.

     

    CountryStyle

     

     


  • Thursday, April 21, 2011 12:42 AM
     
      Has Code

    Yeah that's not valid C# syntax. I typically use vb.net

    Think it's like this

    foreach (DBPhotos photo in GetPhotosFromReader(dataReader))

    {

     photosCollection.Add(photos);

    }


    Ctrl+Z
  • Thursday, April 21, 2011 1:12 AM
     
      Has Code
    Error	8	foreach statement cannot operate on variables of type 'DBPhotos' because 'DBPhotos' does not contain a public definition for 'GetEnumerator'	C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs	2678	13	OmegaLove.Web
    Error	7	'Microsoft.Practices.EnterpriseLibrary.Data.Database': type used in a using statement must be implicitly convertible to 'System.IDisposable'	C:\inetpub\wwwroot\OmegaLove\OmegaLove.Web\Components\DB\SQLOmegaLoveProvider.cs	2674	9	OmegaLove.Web
    

    Mathieu Alexandre Cupryk www.omegalove.com
  • Thursday, April 21, 2011 1:37 AM
     
      Has Code

    trying to stay out of this one.....but I am looking at the data return type of GetPhotosFromReader().  It returns of type DBPhotos:

    private static DBPhotos GetPhotosFromReader(IDataReader dataReader)

     

    Looks like the for statement is basically stating: foreach(DBPhotos photo in DBPhotos)<--this does not sound right, or is it just me?

    The logic should be: foreach(DBPhotos photo in DBPhotosCollection)  OR foreach(DBPhoto photo in DBPhotos)

     

     

    ALSO: if the class did not use an Ienumerable interface then a for loop is the way to enumerate the contents.

     

     

    CountryStyle




  • Thursday, April 21, 2011 4:42 AM
     
      Has Code

     

    It looks like your helper classes trying to encapsulate and abstract things. However it very strange your helper class doesn't offer any provision to manage the resources. No option to see what happen to the opened connection.

    I have only some alternative suggestions. If

    SqlDatabase db = new SqlDatabase(ConnectionString);

    the SqlDatabase object has access to the connection object then have a method in your helper class to close this connection and call it after all of your operations.

    You need to explicitly close the  DataReader at the end of your operations before disposing the connection. Then close connection.

    If your SqlDatabase object handle the connection automatically some way then without knowing the logic nothing we could do. As you can access the DataReader endless time, that indicates the connection is still open. If you have no access to a close method or access to the connection object then simply handle the connection by you and use the helper to only read the Data.  Or else you have find a way to debug (may be in IL) to trace the concurrent connections opened.

    For testing you may increase the connection pool size in your connection string and try. The following code emulate the same situation and give you the same error.

     

     

       for (int i = 0; i < 1200; i++)
       {
        //pass connection string here
        SqlConnection con = new SqlConnection(conStr);
        SqlCommand cmd = new SqlCommand("Your Sql Query here", con);
        con.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        reader.Close();
    }
    So the ultimate solution rely on tracing the opened connection and make ensure it properly closed. All the codes you posted here doesn't show anything about what is going on at the connections. So do you think keep guessing will provide a solution?. The quick way may be think about alternative ways. Good luck

     

     


  • Thursday, April 21, 2011 1:01 PM
     
     
    I will give it a shoot
    Mathieu Alexandre Cupryk www.omegalove.com
  • Friday, April 22, 2011 7:29 PM
     
     
    is there a way I can tell how many connections are open ?
    Mathieu Alexandre Cupryk www.omegalove.com
  • Friday, April 22, 2011 11:16 PM
     
     
    is there a way I can tell how many connections are open ?
    Mathieu Alexandre Cupryk www.omegalove.com
    That would be a function of the database management tools I think.
  • Monday, April 25, 2011 3:37 AM
    Moderator
     
     

    Any update? Would you mind letting us know how it goes?

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.