Help with connection pooling - connections get closed but remain active

Discussion in 'ASP .Net' started by caroh@orange.net, Apr 27, 2005.

  1. Guest

    Can anyone see whats wrong with this code:

    The connections are remaining live in the database: and causing
    "Timeout expired. The timeout period elapsed prior to obtaining a
    connection from the pool" errors.

    Try
    'open the connection
    myConnection.Open()
    'run the query
    myCommand.ExecuteNonQuery()
    Catch ex As SqlException

    Finally
    'close connection
    myConnection.Close()

    End Try

    'Check to see if the service is restricted
    If
    myCommand.Parameters("@AccessRestrictionsSupported").Value.Equals(1)
    Then
    Return True 'service is restricted
    'myConnection.Close()
    Else
    Return False 'service not restricted
    'myConnection.Close()
    End If

    myConnection.Close()

    Any help/suggestions very much appreciated

    Thanks!!
     
    , Apr 27, 2005
    #1
    1. Advertising

  2. close the connection immediatly after the ExecuteNonQuery() method call. You
    don't need the myConnection.Close() at the bottom since the finally block
    will always be executed. When you close a connection it returns to the
    connection pool where it will be destroyed after an idle period of 4 to 7.5
    minutes.

    Where do you exactly get the time-outs?

    Gabriel Lozano-Morán

    <> wrote in message
    news:...
    > Can anyone see whats wrong with this code:
    >
    > The connections are remaining live in the database: and causing
    > "Timeout expired. The timeout period elapsed prior to obtaining a
    > connection from the pool" errors.
    >
    > Try
    > 'open the connection
    > myConnection.Open()
    > 'run the query
    > myCommand.ExecuteNonQuery()
    > Catch ex As SqlException
    >
    > Finally
    > 'close connection
    > myConnection.Close()
    >
    > End Try
    >
    > 'Check to see if the service is restricted
    > If
    > myCommand.Parameters("@AccessRestrictionsSupported").Value.Equals(1)
    > Then
    > Return True 'service is restricted
    > 'myConnection.Close()
    > Else
    > Return False 'service not restricted
    > 'myConnection.Close()
    > End If
    >
    > myConnection.Close()
    >
    > Any help/suggestions very much appreciated
    >
    > Thanks!!
    >
     
    Gabriel Lozano-Morán, Apr 27, 2005
    #2
    1. Advertising

  3. Caro Guest

    Timeouts when users logon to system.

    Checked in enterprise manager - process info and there are lots of
    active connections to the stored procedure that this piece of code
    executes.

    Thanks for your help

    Much appreciated

    "Gabriel Lozano-Morán" <> wrote in message news:<>...
    > close the connection immediatly after the ExecuteNonQuery() method call. You
    > don't need the myConnection.Close() at the bottom since the finally block
    > will always be executed. When you close a connection it returns to the
    > connection pool where it will be destroyed after an idle period of 4 to 7.5
    > minutes.
    >
    > Where do you exactly get the time-outs?
    >
    > Gabriel Lozano-Morán
    >
    > <> wrote in message
    > news:...
    > > Can anyone see whats wrong with this code:
    > >
    > > The connections are remaining live in the database: and causing
    > > "Timeout expired. The timeout period elapsed prior to obtaining a
    > > connection from the pool" errors.
    > >
    > > Try
    > > 'open the connection
    > > myConnection.Open()
    > > 'run the query
    > > myCommand.ExecuteNonQuery()
    > > Catch ex As SqlException
    > >
    > > Finally
    > > 'close connection
    > > myConnection.Close()
    > >
    > > End Try
    > >
    > > 'Check to see if the service is restricted
    > > If
    > > myCommand.Parameters("@AccessRestrictionsSupported").Value.Equals(1)
    > > Then
    > > Return True 'service is restricted
    > > 'myConnection.Close()
    > > Else
    > > Return False 'service not restricted
    > > 'myConnection.Close()
    > > End If
    > >
    > > myConnection.Close()
    > >
    > > Any help/suggestions very much appreciated
    > >
    > > Thanks!!
    > >
     
    Caro, Apr 28, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    0
    Views:
    398
    keithb
    Apr 22, 2006
  2. Norman Swartz
    Replies:
    25
    Views:
    1,210
    Stan McCann
    Apr 3, 2006
  3. Prakhar
    Replies:
    3
    Views:
    308
    Default User
    Jul 19, 2007
  4. Apu Nahasapeemapetilon

    Established connection aborted and underlying connection closed

    Apu Nahasapeemapetilon, Nov 6, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    203
    Apu Nahasapeemapetilon
    Nov 6, 2006
  5. Shin guey Wong
    Replies:
    5
    Views:
    195
    Giles Bowkett
    Dec 17, 2007
Loading...

Share This Page