Results 1 to 9 of 9

Thread: [2005] Connection pool Maximum reached?

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    [2005] Connection pool Maximum reached?

    All,

    I created a VB.NET web application project. Recently I got the dreaded above error message when a certain amount of web pages have loaded. On a form1_Load event, I do this:

    vb Code:
    1. Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
    2.         '
    3.         MyConnection = New SqlConnection
    4.         MyConnection.ConnectionString = CONN_STRING
    5.         MyConnection.Open()
    6.         '
    7.         Me.GridView1.Sort("Priority", SortDirection.Ascending)
    8.         '
    9.     End Sub

    Question: Am I required to explicitly call the .Close? Inside which event would be the appropriate place?

    Will this do the trick - or break anything?

    vb Code:
    1. Protected Sub form1_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Unload
    2.         MyConnection.Close()
    3.         MyConnection = Nothing
    4.     End Sub

    Thanks!

    Dave
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Connection pool Maximum reached?

    Don't leave the connection open in the Load event handler. Open it, use it and close it. That's the way ADO.NET is designed to be used. Create a new connection each time you need one. Connection pooling keeps things efficient.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: [2005] Connection pool Maximum reached?

    Well see now there's the rub. After the page is loaded, I have buttons that do things that require an open connection.

    vb Code:
    1. Protected Sub btnIncrease_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnIncrease.Click
    2.         '
    3.         Try
    4.             '
    5.             MyCommand = New SqlCommand("increasePriority", MyConnection)
    6.             MyCommand.CommandType = CommandType.StoredProcedure
    7.             MyCommand.Parameters.Add("@workOrderNumber", SqlDbType.VarChar).Value = DropDownList_WorkOrders.SelectedValue
    8.             MyDataReader = MyCommand.ExecuteReader()
    9.             '
    10.         Catch ex As Exception
    11.             MsgBox(ex.ToString)
    12.         Finally
    13.             MyDataReader.Close()
    14.         End Try
    15.         '
    16.     End Sub

    Do you suggest I open/close in the beg/end of each of these button's codeblock?

    Thanks!
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Connection pool Maximum reached?

    Quote Originally Posted by Dave Sell
    Do you suggest I open/close in the beg/end of each of these button's codeblock?
    It would appear so.
    Quote Originally Posted by jmcilhinney
    Open it, use it and close it. That's the way ADO.NET is designed to be used. Create a new connection each time you need one.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: [2005] Connection pool Maximum reached?

    OK then thanks, I will do that if that is the standard .NET "good programming practice" in situations like this. I will keep this thread open a tad longer to ensure no new problems arise from it - or if it solves the prob.

    Dave
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2005] Connection pool Maximum reached?

    You might want to look into what JM was saying about the efficiencies of connection pooling keeping things efficient. I may be reading too much into it, but you seem a bit reluctant to open and close connections. I think that was a valid position back in VB6, because there was a pretty good cost to some of that stuff, so leaving one connection open was often a good idea.....as long as your could afford to do so. Times have changed, though, and if you have concerns about this, checking into it a bit might ease your mind on it some.
    My usual boring signature: Nothing

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Connection pool Maximum reached?

    As Shaggy says. With ADO.NET the connections you use are at a high level. There are also connection objects at a much lower level. When you create a connection, open it, use it and discard it, then open a second connection, you will likely be using the same underlying low-level connection. Creating the high-level object is very cheap, so doing so repeatedly is no problem. It's the low-level objects, which you never actually see, that are expensive to create, so they are created and discarded far less often.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: [2005] Connection pool Maximum reached?

    Again, VBF failed to notify me that you guys responded to my posts (this is a long-time issue for me), sorry I just saw your replies.

    Anyway, what I'm hearing is ADO.NET has under-the-hood connection pooling? That would be sweet. I have followed JM's advice from above. I still do not know if there is a problem on the server since I implemented this few weeks back. I will ask my customer how things are going this week.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [2005] Connection pool Maximum reached?

    Quote Originally Posted by jmcilhinney
    Don't leave the connection open in the Load event handler. Open it, use it and close it. That's the way ADO.NET is designed to be used. Create a new connection each time you need one. Connection pooling keeps things efficient.
    To sum it up: Open late, close early.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width