Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > 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.

Reply
Thread Tools

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.

 
 
Guoqi Zheng
Guest
Posts: n/a
 
      06-03-2004
Dear sir,

I keep getting the following errors on one of my sites after clicking for
many times.

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.

Below is my code. Any help will be appreciated.

Dim objReader As SqlDataReader

Dim strConnection As String =
System.Configuration.ConfigurationSettings.AppSett ings("strConnect")

Dim myConnection As SqlConnection = New SqlConnection(strConnection)

Dim myCommand As New SqlCommand("MyProc_XXXX", myConnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim objPara1 As New SqlParameter("@msgId", SqlDbType.Int, 4)

myCommand.Parameters.Add(objPara1)

objPara1.Direction = ParameterDirection.Input

objPara1.Value = MsgId

' Open the connection.

myConnection.Open()

objReader = myCommand.ExecuteReader()



MsgFull.DataSource = objReader

MsgFull.DataBind()

objReader.Close()

objReader = Nothing

myConnection.Close()

myConnection = Nothing


--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com



 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      06-03-2004
This typically happens when connections are not closed after they are used.
Perhaps you have other pieces of code running that do this.

"Guoqi Zheng" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dear sir,
>
> I keep getting the following errors on one of my sites after clicking for
> many times.
>
> 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.
>
> Below is my code. Any help will be appreciated.
>
> Dim objReader As SqlDataReader
>
> Dim strConnection As String =
> System.Configuration.ConfigurationSettings.AppSett ings("strConnect")
>
> Dim myConnection As SqlConnection = New SqlConnection(strConnection)
>
> Dim myCommand As New SqlCommand("MyProc_XXXX", myConnection)
>
> myCommand.CommandType = CommandType.StoredProcedure
>
> Dim objPara1 As New SqlParameter("@msgId", SqlDbType.Int, 4)
>
> myCommand.Parameters.Add(objPara1)
>
> objPara1.Direction = ParameterDirection.Input
>
> objPara1.Value = MsgId
>
> ' Open the connection.
>
> myConnection.Open()
>
> objReader = myCommand.ExecuteReader()
>
>
>
> MsgFull.DataSource = objReader
>
> MsgFull.DataBind()
>
> objReader.Close()
>
> objReader = Nothing
>
> myConnection.Close()
>
> myConnection = Nothing
>
>
> --
> Kind regards
>
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com
>
>
>



 
Reply With Quote
 
 
 
 
Guoqi Zheng
Guest
Posts: n/a
 
      06-03-2004
Thanks for your reply,

I actually really can not find out where I didn't close the connection.

The only Other piece of code which used the connection is below. Do you know
what should I do with it?


Private Function GetMaxPageNr(ByVal fGroupId As Integer, ByVal fPageSize As
Integer) As Integer

Dim ReturnInt As Integer

Dim strConnection As String =
System.Configuration.ConfigurationSettings.AppSett ings("strConnect")

Dim myConnection As SqlConnection = New SqlConnection(strConnection)

Dim myCommand As New SqlCommand("MyProc_TotalPages", myConnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim objPara1 As New SqlParameter("@GroupId", SqlDbType.Int, 4)

myCommand.Parameters.Add(objPara1)

objPara1.Direction = ParameterDirection.Input

objPara1.Value = fGroupId

Dim objPara2 As New SqlParameter("@PageSize", SqlDbType.Int, 4)

myCommand.Parameters.Add(objPara2)

objPara2.Direction = ParameterDirection.Input

objPara2.Value = fPageSize

' for output parameters.

Dim objOutputPara As New SqlParameter("@r", SqlDbType.Int, 4)

myCommand.Parameters.Add(objOutputPara)

objOutputPara.Direction = ParameterDirection.Output

' Open the connection.

myConnection.Open()

myCommand.ExecuteReader()

ReturnInt = objOutputPara.Value

Return ReturnInt

myConnection.Close()

myConnection = Nothing

End Function


--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

"Marina" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This typically happens when connections are not closed after they are

used.
> Perhaps you have other pieces of code running that do this.
>



 
Reply With Quote
 
Marina
Guest
Posts: n/a
 
      06-03-2004
Well, there is your problem:

You have a return statement to return ReturnInt, before you close the
connection. The function exits before the connection is closed - hence the
connection leak.

You should put everything in a try/catch/finally, with the connection being
closed in the Finally to ensure that it always gets closed no matter what.

"Guoqi Zheng" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for your reply,
>
> I actually really can not find out where I didn't close the connection.
>
> The only Other piece of code which used the connection is below. Do you

know
> what should I do with it?
>
>
> Private Function GetMaxPageNr(ByVal fGroupId As Integer, ByVal fPageSize

As
> Integer) As Integer
>
> Dim ReturnInt As Integer
>
> Dim strConnection As String =
> System.Configuration.ConfigurationSettings.AppSett ings("strConnect")
>
> Dim myConnection As SqlConnection = New SqlConnection(strConnection)
>
> Dim myCommand As New SqlCommand("MyProc_TotalPages", myConnection)
>
> myCommand.CommandType = CommandType.StoredProcedure
>
> Dim objPara1 As New SqlParameter("@GroupId", SqlDbType.Int, 4)
>
> myCommand.Parameters.Add(objPara1)
>
> objPara1.Direction = ParameterDirection.Input
>
> objPara1.Value = fGroupId
>
> Dim objPara2 As New SqlParameter("@PageSize", SqlDbType.Int, 4)
>
> myCommand.Parameters.Add(objPara2)
>
> objPara2.Direction = ParameterDirection.Input
>
> objPara2.Value = fPageSize
>
> ' for output parameters.
>
> Dim objOutputPara As New SqlParameter("@r", SqlDbType.Int, 4)
>
> myCommand.Parameters.Add(objOutputPara)
>
> objOutputPara.Direction = ParameterDirection.Output
>
> ' Open the connection.
>
> myConnection.Open()
>
> myCommand.ExecuteReader()
>
> ReturnInt = objOutputPara.Value
>
> Return ReturnInt
>
> myConnection.Close()
>
> myConnection = Nothing
>
> End Function
>
>
> --
> Kind regards
>
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com
>
> "Marina" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > This typically happens when connections are not closed after they are

> used.
> > Perhaps you have other pieces of code running that do this.
> >

>
>



 
Reply With Quote
 
Guoqi Zheng
Guest
Posts: n/a
 
      06-03-2004
Thanks for your quick reply, will try it..


--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

"Marina" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Well, there is your problem:
>
> You have a return statement to return ReturnInt, before you close the
> connection. The function exits before the connection is closed - hence the
> connection leak.
>
> You should put everything in a try/catch/finally, with the connection

being
> closed in the Finally to ensure that it always gets closed no matter what.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Troubleshooting Timeout expired. All pooled connections were in use and max pool size was reached. jobs ASP .Net 1 11-10-2007 02:54 AM
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Ersin Gençtürk ASP .Net 1 09-25-2007 07:33 AM
Error when load testing web application: all pooled connections were in use or max pool size was reached Allan Ebdrup ASP .Net 1 05-14-2007 10:43 AM
'Timeout period elapsed prior to obtaining a connection from the pool.' - Please help. UJ ASP .Net 1 02-10-2006 01:09 PM
Re: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Bob Johnson ASP .Net 0 08-07-2003 12:52 PM



Advertisments