locked
Timer control showing -timeout period elapsed error after few minutes RRS feed

  • Question

  • User-1578974752 posted

    The Test paper is having Time .My issue is

    after 4 to 5 minutes showing error .I have closed all connections using con.close()

    still it is coming .The session time in web config I set to 45 minutes as below. The real test will take 45 minutes. How can I solve this . Appreciate the help

    <sessionState timeout="45"></sessionState>

    </system.web>

    Error showing is as below

    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.'

    Protected Sub tmrMain_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles tmrMain.Tick

    Dim timer As UI.Timer = sender

    ' set current time

    Me.txbCurrentTime.Text = DateTime.Now.ToString

    ' set anchor time by timer control

    Me.txbExecutedTime.Text = Me.txbExecutedTime.Text * 1000 - timer.Interval

    ' show remain executed time

    Me.txbExecutedTime.Text = Me.txbExecutedTime.Text / 1000

    'If Me.txbExecutedTime.Text = 0 Then

    ' ' stop timer control

    ' timer.Enabled = False

    ' ' Redirecting to anther page

    ' Response.Redirect("")

    'End If

    If Me.txbExecutedTime.Text = 600 Then

    ' stop timer control

    ' timer.Enabled = False

    ' Redirecting to anther page

    ' Response.Write("<script>alert('Only 10 minutes Left')</script>")

    MsgBox("Only 10 minutes Left")

    End If

    If Me.txbExecutedTime.Text = 0 Then

    ' stop timer control

    ' timer.Enabled = False

    ' Redirecting to anther page

    Response.Redirect("Result.aspx")

    End If

    End Sub

    <asp:UpdatePanel ID="upMain" runat="server">

    <ContentTemplate>

    <table>

    <tr>

    <td class="auto-style149">

    <asp:Label ID="Label3" runat="server" Width="140px" Text="Current Time" Visible="False"></asp:Label>

    </td>

    <td class="auto-style147">

    <asp:TextBox ID="txbCurrentTime" runat="server" Width="200px"></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td class="auto-style149">Time Left&nbsp; [Sec]</td>

    <td class="auto-style147">

    <asp:TextBox ID="txbExecutedTime" runat="server" AutoPostBack="True" Width="200px"></asp:TextBox>

    </td>

    </tr>

    </table>

    <asp:Timer ID="tmrMain" runat="server" Enabled="False" Interval="1000">

    </asp:Timer>

    </ContentTemplate>

    <Triggers>

    <asp:AsyncPostBackTrigger ControlID="tmrMain" EventName="Tick" />

    <asp:AsyncPostBackTrigger ControlID="txbExecutedTime" EventName="TextChanged" />

    </Triggers>

    </asp:UpdatePanel>

    Thursday, September 6, 2018 3:44 AM

Answers

  • User475983607 posted

    Error showing is as below

    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.

    This error is usually related to not closing DB connections.  Are you making a DB connection in the Page_Load?

    The error message always shows the line of code that cause the error in the stack trace... What is that line?

    By the way, this code will not work as expected on an actual web server.  It works on your machine because it is both the web server and the client.

    MsgBox("Only 10 minutes Left")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 6, 2018 1:57 PM

All replies

  • User475983607 posted

    Error showing is as below

    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.

    This error is usually related to not closing DB connections.  Are you making a DB connection in the Page_Load?

    The error message always shows the line of code that cause the error in the stack trace... What is that line?

    By the way, this code will not work as expected on an actual web server.  It works on your machine because it is both the web server and the client.

    MsgBox("Only 10 minutes Left")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 6, 2018 1:57 PM
  • User-1578974752 posted

    Thanks mgebhard .When I take out the connection string from pagelaod error is gone.

    The error showing was in con.Open() and Yes ,it was placed in page load.There are Save,submit and Finish Buttons in the Form.Con.open is placed in the page load hence I don't want to add connection string in the save,submit etc.Timer is also attached in this form.so if I take out connection string from page load I will have to place the connection string in each Buttons repeatedly right? or is there any other way instead of repeatedly placing the connection string

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    con = New SqlConnection("Data Source=10.170.10.26;Initial Catalog=Test;Persist Security Info=True;User ID=xxx;Password=xxxx")

    con.Open()

    Try

    cmd = New SqlCommand

    cmd.Connection = con

    cmd.CommandText = "select * FROM ABMaster where ABMasterID = '" + qusetid.Text + "'"

    drd = cmd.ExecuteReader

    If drd.HasRows = True Then

    drd.Read()

    Duration.Text = drd.Item("Duration")

    correctansmark.Text = drd.Item("correctanswermark")

    End If

    Catch ex As Exception

    Label2.Text = ex.Message()

    Finally

    cmd.Dispose()

    drd.Close()

    con.Close()

    End Try

     End Sub

    Friday, September 7, 2018 1:50 AM
  • User-893317190 posted

    Hi shsu,

    If you don't want to declare your connectionstring in every method, you could declare it outside the method so that all methods of  the class could share it.

    Also you could read your connectionstring from web.config through the class ConfigurationManager.

    Below is my code.

    Private Shared connectionString = ConfigurationManager.ConnectionStrings("bjhksjConnectionString").ConnectionString
        Private Shared connectionString2 = "Data Source=.;Initial Catalog=bjhksj;Integrated Security=True"
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub Button1_Click(sender As Object, e As EventArgs)
            Using con As SqlConnection = New SqlConnection(connectionString)
    
                Dim Sql As String = "select * from VBPlan"
                Using com As SqlCommand = New SqlCommand(Sql, con)
    
                    con.Open()
                    Using reader As SqlDataReader = com.ExecuteReader()
    
                        If reader.HasRows Then
                            reader.Read()
                            Label1.Text = reader.Item("id").ToString()
                        End If
    
                    End Using
                End Using
            End Using
    
        End Sub

    And connectionstring in web.config

    <configuration>
      <connectionStrings>
        <add name="bjhksjConnectionString" connectionString="Data Source=.;Initial Catalog=bjhksj;Integrated Security=True"
          providerName="System.Data.SqlClient" />
        <add name="EntityExeConnectionString" connectionString="Data Source=.;Initial Catalog=EntityExe;Integrated Security=True"
          providerName="System.Data.SqlClient" />
      </connectionStrings>

    For more information about configurationManager, please refer to

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-strings-and-configuration-files

    As you could see, I haven't written  try catch and write using instead. The keyword using could help you release resource and catch exception just as you write try catch and finally.

    For more information about using , please refer to  

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement

    Best regards,

    Ackerly Xu

    Friday, September 7, 2018 5:28 AM