Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

I keep getting this error:

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.

Note:
Already tried to adjust connection time. The results was the windows application form is hanging. How do I expand the pool size that is said in the error? The maximum value of a loop that will save in a database is 250. :|

Sample:
VB
For x As Integer = 0 To (250 - 1)
InsertToDB(pnNumber, dateOfPay, Math.Round(principal_payments, 2), Math.Round(interest_payments, 2), Math.Round(monthly_payment, 2), Math.Round(balance, 2))
Next


VB
Private Sub InsertToDB(ByVal pnNumber As String, ByVal dateOfPayment As String, ByVal principalAmount As Double, ByVal interestAmount As Double,
                           ByVal monthlyPayment As Double, ByVal balance As Double)

        'MessageBox.Show(pnNumber + ", " +
        '                Convert.ToString(dateOfPayment) + ", " +
        '                Convert.ToString(principalAmount) + ", " +
        '                Convert.ToString(interestAmount) + ", " +
        '                Convert.ToString(monthlyPayment) + ", " +
        '                Convert.ToString(balance) + ", " +
        '                DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ", " +
        '                userid)
        Try
            Dim conn As SqlConnection
            Dim comm As SqlCommand
            Dim reader As SqlDataReader
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("msSqlConnectionString1").ConnectionString
            conn = New SqlConnection(connectionString)
            comm = New SqlCommand()

            comm.Connection = conn

            comm.CommandType = CommandType.StoredProcedure

            comm.CommandText = "sp_SetPNAmort"

            comm.Parameters.Add("@PNNumber", Data.SqlDbType.NVarChar)
            comm.Parameters.Add("@periodDate", Data.SqlDbType.NVarChar)
            comm.Parameters.Add("@principalAmount", Data.SqlDbType.Float)
            comm.Parameters.Add("@interestAmount", Data.SqlDbType.Float)
            comm.Parameters.Add("@payment", Data.SqlDbType.Float)
            comm.Parameters.Add("@osBalance", Data.SqlDbType.Float)
            comm.Parameters.Add("@dateGenerated", Data.SqlDbType.NVarChar)
            comm.Parameters.Add("@uploadedBy", Data.SqlDbType.NVarChar)

            comm.Parameters("@PNNumber").Value = pnNumber
            comm.Parameters("@periodDate").Value = dateOfPayment
            comm.Parameters("@principalAmount").Value = principalAmount
            comm.Parameters("@interestAmount").Value = interestAmount
            comm.Parameters("@payment").Value = monthlyPayment
            comm.Parameters("@osBalance").Value = balance
            comm.Parameters("@dateGenerated").Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
            comm.Parameters("@uploadedBy").Value = userid

            conn.Open()
            reader = comm.ExecuteReader()
            reader.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Alert!!!")
        End Try
        

    End Sub
Posted
Updated 14-Jul-14 19:21pm
v2
Comments
ArunRajendra 14-Jul-14 23:05pm    
Are you sure that connection pool is a problem. I guess the problem is with connction not being closed.
mitchiee1226 15-Jul-14 1:21am    
Updated the question for you. :)

it can be the

1. Connection not closed
2. Deadlock somewhere
3. Database optimal query plan / stats

To check Deadlock Connect to your database with Sql Server Management Studio. In the left pane right-click on the server node and select Activity Monitor. Take a look at the running processes. Normally most will be idle or running. When the problem occurs you can identify any blocked process by the process state. If you right-click on the process and select details it'll show you the last query executed by the process.

SQL
The second issue will cause the database to use a sub-optimal query plan. It can be resolved by clearing the statistics:

exec sp_updatestats
 
Share this answer
 
Comments
mitchiee1226 15-Jul-14 1:28am    
Run the exec sp_updatestats, it still did not work.
Hi,

Please make Some changes in Connection String

1. define min pool size and Max pool size

2. define Connection Time Out Time

Both settings will be in the connection String. Please change, check and confirm.
 
Share this answer
 
Try putting close after reader si closed. You also do some code reorganization so that connection will be closed in finally block.

VB
conn.Close()


http://msdn.microsoft.com/en-us/library/fk6t46tz.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900