Trap "connection pool" errors

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Trap "connection pool" errors

    We have implemented unhandled error trapping at the application level and
    log these errors to our database. One error, however, the does not get
    trapped is when the connection pool has exceeded the max number of
    connections.

    Obviously, we need to find the place(s) in our code where connections are
    not closed correctly (espcially in loops), but I'm wondering if it's
    possible to trap this error and to find out which part of our code (i.e.
    stack trace) caused it. It seems logical that the application itself does
    not produce the error since there is no error in the codebehind file. Is it
    more of an IIS-level error?

    Thanks in advance for your thoughts.

    Sean


    Sean Nolan Guest

  2. Similar Questions and Discussions

    1. "Contribute cannot verify your connection information."on a Local / Network connection
      When I create a connection key and specify Local/Network for the website, then select the right folder, I get this error: "Contribute cannot...
    2. "Contribute cannot verify your connection information"- Every other problem ruled out, but still no connection
      Hi, first, please allow me to give you the background info Client OS - Windows 2000/XP Pro Version - Contribute 2.01 - I installed the patch from...
    3. 2 errors: "The parameter is incorrect" and "Overlapped I/O operation is in progress."
      Hello, I am writing an ASP app which is giving me some very frustrating errors. They appear intermittently, no real pattern to them, and often...
    4. Pop-up window errors:"translators not loaded due to errors"
      I keep getting pop-up windows when using DWMX....any suggestions as to how to fix this type of error? The pop-up says: at line 16...
    5. "Connection Reset by Peer" or "hang"
      (Original Post: http://www.knoppix.net/forum/viewtopic.php?t=3745) Here is my problem: I am trying to install a software (Steam), and from time...
  3. #2

    Default Re: Trap "connection pool" errors


    "Sean Nolan" <snolan@harriton.com> wrote in message
    news:Oa7doR7RDHA.3768@tk2msftngp13.phx.gbl...
    > We have implemented unhandled error trapping at the application level and
    > log these errors to our database. One error, however, the does not get
    > trapped is when the connection pool has exceeded the max number of
    > connections.
    >
    > Obviously, we need to find the place(s) in our code where connections are
    > not closed correctly (espcially in loops), but I'm wondering if it's
    > possible to trap this error and to find out which part of our code (i.e.
    > stack trace) caused it.
    It it possible. The general idea is to have a object that will be Garbage
    Collected in the same pass as your connection. Whenever a connection is
    opened, store the stack trace of the opening method. And put a finalizer on
    that object, and write out a trace entry if the finalizer runs and the
    connection is still open.

    One way to do this is to have a "wrapper object" for your connection.
    But then your app code has to create the wrapper instead of the connection.
    I think this is a good thing, since you can implement all the DAAB methods
    as instance methods of your wrapper object. But that's another story.

    Assuming you are using SQLServer (or some other connection that has a
    StateChanged event), there may be an easier way.

    Without a wrapper object, to get an object which will be finalized at the
    same time as the connection we can use a "spy" object.

    If we have a "spy" object which handles the StateChaned event of the
    SQLConnection, and we give the spy object a reference to the connection we
    will have what we want. If 2 objects mutually refer to each other, then
    they will always be GC'd at the same time. The spy refers to the
    SQLConnection and since the spy handles an event on teh SQLConnection, the
    SQLConnection's delegate list contains a reference to the spy object. Voila!

    There follows sample program to do this.

    David

    Imports System.Data.SqlClient

    Class ConnectionFactory
    Private Class ConnectionSpy
    Private con As SqlConnection
    Dim st As StackTrace
    Public Sub New(ByVal con As SqlConnection, ByVal st As StackTrace)
    Me.st = st

    'latch on to the connection
    Me.con = con
    AddHandler con.StateChange, AddressOf StateChange
    End Sub
    Public Sub StateChange(ByVal sender As Object, ByVal args As
    System.Data.StateChangeEventArgs)
    If args.CurrentState = ConnectionState.Closed Then
    'detach the spy object and let it float away into space
    GC.SuppressFinalize(Me)
    RemoveHandler con.StateChange, AddressOf StateChange
    con = Nothing
    st = Nothing
    End If
    End Sub
    Protected Overrides Sub Finalize()
    'if we got here then the connection was not closed.
    Trace.WriteLine("WARNING: Open SQLConnection is being Garbage
    Collected")
    Trace.WriteLine("The connection was initially opened " & st.ToString)
    End Sub
    End Class

    Public Shared Function OpenConnection(ByVal connect As String) As
    SqlConnection
    Dim con As New SqlConnection(connect)
    con.Open()
    Dim st As New StackTrace(True)
    Dim sl As New ConnectionSpy(con, st)

    Return con
    End Function

    End Class


    Module Module1

    Sub Main()
    'pipe trace output to the console
    'in your app this would go to a trace file
    System.Diagnostics.Trace.Listeners.Add(New
    TextWriterTraceListener(System.Console.Out))
    Dim connect As String = "..."


    Dim c As SqlConnection = ConnectionFactory.OpenConnection(connect)
    c = Nothing '!!the connection was not closed

    c = ConnectionFactory.OpenConnection(connect)
    c.Close() 'this time it was closed
    c = Nothing

    GC.Collect(GC.MaxGeneration)
    GC.WaitForPendingFinalizers()
    'output will show 1 warning


    End Sub

    End Module



    David Browne Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139