connection pooling error

Discussion in 'ASP .Net' started by Chris Szabo, Aug 19, 2003.

  1. Chris Szabo

    Chris Szabo Guest

    I've created a data access layer for a .NET web
    application. I'm using C# and framework 1.1. I'm getting
    an error from time to time when I close a connection
    saying: System.InvalidOperationException: A connection
    pooling error has occurred.

    It doesn't happen each time, the exception is thrown
    randomly. The big problem is that the connection is left
    active in the pool. After a short period of time, the
    pool is filled up and people can't access the site.

    Has anyone ever run into this before? Any ideas on how I
    might correct the problem? Any help is greatly
    appreciated.

    Chris Szabo.
    Chris Szabo, Aug 19, 2003
    #1
    1. Advertising

  2. Chris Szabo

    Frank Drebin Guest

    Can post some code? How are you accessing and releasing your connection??

    "Chris Szabo" <> wrote in message
    news:26bc01c36674$55f365c0$...
    > I've created a data access layer for a .NET web
    > application. I'm using C# and framework 1.1. I'm getting
    > an error from time to time when I close a connection
    > saying: System.InvalidOperationException: A connection
    > pooling error has occurred.
    >
    > It doesn't happen each time, the exception is thrown
    > randomly. The big problem is that the connection is left
    > active in the pool. After a short period of time, the
    > pool is filled up and people can't access the site.
    >
    > Has anyone ever run into this before? Any ideas on how I
    > might correct the problem? Any help is greatly
    > appreciated.
    >
    > Chris Szabo.
    Frank Drebin, Aug 19, 2003
    #2
    1. Advertising

  3. Chris Szabo

    Chris Szabo Guest

    Sure... here's some code.

    private void killConn()
    {
    if (cmdSQL.Connection != null)
    {
    try
    {
    cmdSQL.Connection.Close();
    cmdSQL.Connection.Dispose();
    }
    catch ( Exception e )
    {
    l.writeException ( e );
    }
    }
    }

    public SqlCommand cmdSQL
    {
    get
    {
    if ( _cmdSQL == null )
    _cmdSQL = new SqlCommand ( );

    if ( _cmdSQL.Connection == null )
    _cmdSQL.Connection = new SqlConnection(connString);

    if ( _cmdSQL.Connection.ConnectionString == null ||
    _cmdSQL.Connection.ConnectionString==String.Empty )
    _cmdSQL.Connection.ConnectionString = connString;

    if ( _cmdSQL.Connection.State ==
    ConnectionState.Closed )
    {
    try
    {
    _cmdSQL.Connection.Open ( );
    }
    catch ( Exception e )
    {
    l.writeException ( e );
    }
    }
    return _cmdSQL;
    }
    }

    >-----Original Message-----
    >Can post some code? How are you accessing and releasing

    your connection??
    >
    >"Chris Szabo" <> wrote

    in message
    >news:26bc01c36674$55f365c0$...
    >> I've created a data access layer for a .NET web
    >> application. I'm using C# and framework 1.1. I'm

    getting
    >> an error from time to time when I close a connection
    >> saying: System.InvalidOperationException: A connection
    >> pooling error has occurred.
    >>
    >> It doesn't happen each time, the exception is thrown
    >> randomly. The big problem is that the connection is

    left
    >> active in the pool. After a short period of time, the
    >> pool is filled up and people can't access the site.
    >>
    >> Has anyone ever run into this before? Any ideas on how

    I
    >> might correct the problem? Any help is greatly
    >> appreciated.
    >>
    >> Chris Szabo.

    >
    >
    >.
    >
    Chris Szabo, Aug 19, 2003
    #3
  4. Chris Szabo

    Frank Drebin Guest

    Hmm... some things to consider..

    You could use the "Singleton" pattern and have a static connection that gets
    reused because really - you can have multiple operations happen over one
    connection. if you do this, everytime before you make a SQL call, make sure
    the connection is open, if it's not - then open it.

    but the first thing that came to mind is that you are trying to manually
    ..Dispose() of the object, and for connection pooling - it seems to be all or
    nothing. Either you control all connections opening or closing - or you let
    cp handle it.. So I'd say get comment out the .Dispose() and see if this
    still happens..

    And if the database is SQL2K - you can run the SQL Profiler and watch the
    connections and see what happens every time there is a new connection..

    hth

    "Chris Szabo" <> wrote in message
    news:013101c36679$bb1fdf50$...
    > Sure... here's some code.
    >
    > private void killConn()
    > {
    > if (cmdSQL.Connection != null)
    > {
    > try
    > {
    > cmdSQL.Connection.Close();
    > cmdSQL.Connection.Dispose();
    > }
    > catch ( Exception e )
    > {
    > l.writeException ( e );
    > }
    > }
    > }
    >
    > public SqlCommand cmdSQL
    > {
    > get
    > {
    > if ( _cmdSQL == null )
    > _cmdSQL = new SqlCommand ( );
    >
    > if ( _cmdSQL.Connection == null )
    > _cmdSQL.Connection = new SqlConnection(connString);
    >
    > if ( _cmdSQL.Connection.ConnectionString == null ||
    > _cmdSQL.Connection.ConnectionString==String.Empty )
    > _cmdSQL.Connection.ConnectionString = connString;
    >
    > if ( _cmdSQL.Connection.State ==
    > ConnectionState.Closed )
    > {
    > try
    > {
    > _cmdSQL.Connection.Open ( );
    > }
    > catch ( Exception e )
    > {
    > l.writeException ( e );
    > }
    > }
    > return _cmdSQL;
    > }
    > }
    >
    > >-----Original Message-----
    > >Can post some code? How are you accessing and releasing

    > your connection??
    > >
    > >"Chris Szabo" <> wrote

    > in message
    > >news:26bc01c36674$55f365c0$...
    > >> I've created a data access layer for a .NET web
    > >> application. I'm using C# and framework 1.1. I'm

    > getting
    > >> an error from time to time when I close a connection
    > >> saying: System.InvalidOperationException: A connection
    > >> pooling error has occurred.
    > >>
    > >> It doesn't happen each time, the exception is thrown
    > >> randomly. The big problem is that the connection is

    > left
    > >> active in the pool. After a short period of time, the
    > >> pool is filled up and people can't access the site.
    > >>
    > >> Has anyone ever run into this before? Any ideas on how

    > I
    > >> might correct the problem? Any help is greatly
    > >> appreciated.
    > >>
    > >> Chris Szabo.

    > >
    > >
    > >.
    > >
    Frank Drebin, Aug 19, 2003
    #4
  5. Chris Szabo

    Chris Szabo Guest

    Okay, I'll give that a try. Can you fill me in on
    the "Singleton" pattern? I've actually been trying to
    accomplish this since we expect massive amounts of traffic
    on the site. I haven't been able to come up with anything.

    Thanks,
    Chris Szabo.

    >-----Original Message-----
    >Hmm... some things to consider..
    >
    >You could use the "Singleton" pattern and have a static

    connection that gets
    >reused because really - you can have multiple operations

    happen over one
    >connection. if you do this, everytime before you make a

    SQL call, make sure
    >the connection is open, if it's not - then open it.
    >
    >but the first thing that came to mind is that you are

    trying to manually
    >..Dispose() of the object, and for connection pooling -

    it seems to be all or
    >nothing. Either you control all connections opening or

    closing - or you let
    >cp handle it.. So I'd say get comment out the .Dispose()

    and see if this
    >still happens..
    >
    >And if the database is SQL2K - you can run the SQL

    Profiler and watch the
    >connections and see what happens every time there is a

    new connection..
    >
    >hth
    >
    >"Chris Szabo" <> wrote

    in message
    >news:013101c36679$bb1fdf50$...
    >> Sure... here's some code.
    >>
    >> private void killConn()
    >> {
    >> if (cmdSQL.Connection != null)
    >> {
    >> try
    >> {
    >> cmdSQL.Connection.Close();
    >> cmdSQL.Connection.Dispose();
    >> }
    >> catch ( Exception e )
    >> {
    >> l.writeException ( e );
    >> }
    >> }
    >> }
    >>
    >> public SqlCommand cmdSQL
    >> {
    >> get
    >> {
    >> if ( _cmdSQL == null )
    >> _cmdSQL = new SqlCommand ( );
    >>
    >> if ( _cmdSQL.Connection == null )
    >> _cmdSQL.Connection = new SqlConnection(connString);
    >>
    >> if ( _cmdSQL.Connection.ConnectionString == null

    ||
    >>

    _cmdSQL.Connection.ConnectionString==String.Empty )
    >> _cmdSQL.Connection.ConnectionString = connString;
    >>
    >> if ( _cmdSQL.Connection.State ==
    >>

    ConnectionState.Closed )
    >> {
    >> try
    >> {
    >> _cmdSQL.Connection.Open ( );
    >> }
    >> catch ( Exception e )
    >> {
    >> l.writeException ( e );
    >> }
    >> }
    >> return _cmdSQL;
    >> }
    >> }
    >>
    >> >-----Original Message-----
    >> >Can post some code? How are you accessing and releasing

    >> your connection??
    >> >
    >> >"Chris Szabo" <> wrote

    >> in message
    >> >news:26bc01c36674$55f365c0$...
    >> >> I've created a data access layer for a .NET web
    >> >> application. I'm using C# and framework 1.1. I'm

    >> getting
    >> >> an error from time to time when I close a connection
    >> >> saying: System.InvalidOperationException: A

    connection
    >> >> pooling error has occurred.
    >> >>
    >> >> It doesn't happen each time, the exception is thrown
    >> >> randomly. The big problem is that the connection is

    >> left
    >> >> active in the pool. After a short period of time,

    the
    >> >> pool is filled up and people can't access the site.
    >> >>
    >> >> Has anyone ever run into this before? Any ideas on

    how
    >> I
    >> >> might correct the problem? Any help is greatly
    >> >> appreciated.
    >> >>
    >> >> Chris Szabo.
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >
    Chris Szabo, Aug 19, 2003
    #5
  6. Kill cmdSQL.Connection.Dispose(); GC issue, with Dispose() left alive
    until blah blah blah maybe?


    "Chris Szabo" <> wrote in message
    news:013101c36679$bb1fdf50$...
    > Sure... here's some code.
    >
    > private void killConn()
    > {
    > if (cmdSQL.Connection != null)
    > {
    > try
    > {
    > cmdSQL.Connection.Close();
    > cmdSQL.Connection.Dispose();
    > }
    > catch ( Exception e )
    > {
    > l.writeException ( e );
    > }
    > }
    > }
    >
    > public SqlCommand cmdSQL
    > {
    > get
    > {
    > if ( _cmdSQL == null )
    > _cmdSQL = new SqlCommand ( );
    >
    > if ( _cmdSQL.Connection == null )
    > _cmdSQL.Connection = new SqlConnection(connString);
    >
    > if ( _cmdSQL.Connection.ConnectionString == null ||
    > _cmdSQL.Connection.ConnectionString==String.Empty )
    > _cmdSQL.Connection.ConnectionString = connString;
    >
    > if ( _cmdSQL.Connection.State ==
    > ConnectionState.Closed )
    > {
    > try
    > {
    > _cmdSQL.Connection.Open ( );
    > }
    > catch ( Exception e )
    > {
    > l.writeException ( e );
    > }
    > }
    > return _cmdSQL;
    > }
    > }
    >
    > >-----Original Message-----
    > >Can post some code? How are you accessing and releasing

    > your connection??
    > >
    > >"Chris Szabo" <> wrote

    > in message
    > >news:26bc01c36674$55f365c0$...
    > >> I've created a data access layer for a .NET web
    > >> application. I'm using C# and framework 1.1. I'm

    > getting
    > >> an error from time to time when I close a connection
    > >> saying: System.InvalidOperationException: A connection
    > >> pooling error has occurred.
    > >>
    > >> It doesn't happen each time, the exception is thrown
    > >> randomly. The big problem is that the connection is

    > left
    > >> active in the pool. After a short period of time, the
    > >> pool is filled up and people can't access the site.
    > >>
    > >> Has anyone ever run into this before? Any ideas on how

    > I
    > >> might correct the problem? Any help is greatly
    > >> appreciated.
    > >>
    > >> Chris Szabo.

    > >
    > >
    > >.
    > >
    MS News \(MS ILM\), Aug 19, 2003
    #6
  7. Chris Szabo

    Chris Szabo Guest

    I've modified the code as follows and I'm still getting
    the same error. I can actually step through it, verify
    that _cmdSQL is not null, .Connection is not null, and the
    state is open. When I reach the try catch block an
    exception is still thrown, A connection pooling error has
    occurred.

    private void killConn()
    {
    if ( _cmdSQL != null )
    {
    if ( _cmdSQL.Connection != null )
    {
    if ( _cmdSQL.Connection.State !=
    ConnectionState.Closed )
    {
    try
    {
    _cmdSQL.Connection.Close();
    }
    catch ( Exception e )
    {
    l.writeException ( e );
    }
    }
    }
    }
    }

    Any more ideas...?

    >-----Original Message-----
    >Okay, I'll give that a try. Can you fill me in on
    >the "Singleton" pattern? I've actually been trying to
    >accomplish this since we expect massive amounts of

    traffic
    >on the site. I haven't been able to come up with

    anything.
    >
    >Thanks,
    >Chris Szabo.
    >
    >>-----Original Message-----
    >>Hmm... some things to consider..
    >>
    >>You could use the "Singleton" pattern and have a static

    >connection that gets
    >>reused because really - you can have multiple operations

    >happen over one
    >>connection. if you do this, everytime before you make a

    >SQL call, make sure
    >>the connection is open, if it's not - then open it.
    >>
    >>but the first thing that came to mind is that you are

    >trying to manually
    >>..Dispose() of the object, and for connection pooling -

    >it seems to be all or
    >>nothing. Either you control all connections opening or

    >closing - or you let
    >>cp handle it.. So I'd say get comment out the .Dispose()

    >and see if this
    >>still happens..
    >>
    >>And if the database is SQL2K - you can run the SQL

    >Profiler and watch the
    >>connections and see what happens every time there is a

    >new connection..
    >>
    >>hth
    >>
    >>"Chris Szabo" <> wrote

    >in message
    >>news:013101c36679$bb1fdf50$...
    >>> Sure... here's some code.
    >>>
    >>> private void killConn()
    >>> {
    >>> if (cmdSQL.Connection != null)
    >>> {
    >>> try
    >>> {
    >>> cmdSQL.Connection.Close();
    >>> cmdSQL.Connection.Dispose();
    >>> }
    >>> catch ( Exception e )
    >>> {
    >>> l.writeException ( e );
    >>> }
    >>> }
    >>> }
    >>>
    >>> public SqlCommand cmdSQL
    >>> {
    >>> get
    >>> {
    >>> if ( _cmdSQL == null )
    >>> _cmdSQL = new SqlCommand ( );
    >>>
    >>> if ( _cmdSQL.Connection == null )
    >>> _cmdSQL.Connection = new SqlConnection(connString);
    >>>
    >>> if ( _cmdSQL.Connection.ConnectionString == null

    >||
    >>>

    >_cmdSQL.Connection.ConnectionString==String.Empty )
    >>> _cmdSQL.Connection.ConnectionString = connString;
    >>>
    >>> if ( _cmdSQL.Connection.State ==
    >>>

    >ConnectionState.Closed )
    >>> {
    >>> try
    >>> {
    >>> _cmdSQL.Connection.Open ( );
    >>> }
    >>> catch ( Exception e )
    >>> {
    >>> l.writeException ( e );
    >>> }
    >>> }
    >>> return _cmdSQL;
    >>> }
    >>> }
    >>>
    >>> >-----Original Message-----
    >>> >Can post some code? How are you accessing and

    releasing
    >>> your connection??
    >>> >
    >>> >"Chris Szabo" <>

    wrote
    >>> in message
    >>> >news:26bc01c36674$55f365c0$...
    >>> >> I've created a data access layer for a .NET web
    >>> >> application. I'm using C# and framework 1.1. I'm
    >>> getting
    >>> >> an error from time to time when I close a connection
    >>> >> saying: System.InvalidOperationException: A

    >connection
    >>> >> pooling error has occurred.
    >>> >>
    >>> >> It doesn't happen each time, the exception is thrown
    >>> >> randomly. The big problem is that the connection is
    >>> left
    >>> >> active in the pool. After a short period of time,

    >the
    >>> >> pool is filled up and people can't access the site.
    >>> >>
    >>> >> Has anyone ever run into this before? Any ideas on

    >how
    >>> I
    >>> >> might correct the problem? Any help is greatly
    >>> >> appreciated.
    >>> >>
    >>> >> Chris Szabo.
    >>> >
    >>> >
    >>> >.
    >>> >

    >>
    >>
    >>.
    >>

    >.
    >
    Chris Szabo, Aug 19, 2003
    #7
    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. Trevor Hartman

    connection pooling

    Trevor Hartman, Jul 28, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    547
    Mark Heimonen
    Jul 28, 2003
  2. William \(Bill\) Vaughn

    Re: SqlConnection and connection pooling

    William \(Bill\) Vaughn, Nov 14, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    486
    William \(Bill\) Vaughn
    Nov 14, 2003
  3. =?Utf-8?B?UGllcnNvbiBD?=

    Connection Pooling, Dispose/Close/Using

    =?Utf-8?B?UGllcnNvbiBD?=, Oct 14, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    4,584
    speedy
    Nov 26, 2008
  4. =?Utf-8?B?VmFtJHk=?=

    Connection pooling

    =?Utf-8?B?VmFtJHk=?=, Nov 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    478
    Patrice
    Nov 24, 2004
  5. shahzad

    Connection Pooling Error

    shahzad, Apr 4, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    351
    George Ter-Saakov
    Apr 4, 2008
Loading...

Share This Page