use of MySQLConnection.dispose and/or MySQLCommand.dispose

Discussion in 'ASP .Net' started by Antonio Concepcion, Feb 17, 2005.

  1. Hi!
    After you close the SQL Connection using

    MySQLConnection.Close

    Do you still need to do a dispose as in:

    MySQLConnection.Dispose
    and also
    MySQLCommand.Dispose?

    Is this good practice?

    Thanks
    Antonio Concepcion
     
    Antonio Concepcion, Feb 17, 2005
    #1
    1. Advertising

  2. Antonio Concepcion

    Tod Birdsall Guest

    Hi Antonio,

    If you view the SqlConnection Dispose() method using a disassembler (I
    use .NET Reflector) you will see that all it does is check to see if
    the ConnectionState is open and if it is, it calls the Close() method.

    So, to answer your question, if you call Close() yourself, there is no
    need to call the Dispose() method.

    Tod Birdsall, MCP
    http://tod1d.blogspot.com
     
    Tod Birdsall, Feb 17, 2005
    #2
    1. Advertising

  3. Well, there really is more to it than that. By default, the connection
    pooling is on. The default behavior of close flags the connection object as
    reusable and returns it to the connection pool. After 60 seconds (default
    timeout), the connection is truly closed. A closed connection may then have
    the managed memory reclaimed. So either call has the same effect underneath
    as rightly pointed out.

    --
    Regards,
    Alvin Bruney [Microsoft MVP ASP.NET]

    [Shameless Author plug]
    The Microsoft Office Web Components Black Book with .NET
    Now Available @ http://www.lulu.com/owc
    ----------------------------------------------------------


    "Tod Birdsall" <> wrote in message
    news:...
    > Hi Antonio,
    >
    > If you view the SqlConnection Dispose() method using a disassembler (I
    > use .NET Reflector) you will see that all it does is check to see if
    > the ConnectionState is open and if it is, it calls the Close() method.
    >
    > So, to answer your question, if you call Close() yourself, there is no
    > need to call the Dispose() method.
    >
    > Tod Birdsall, MCP
    > http://tod1d.blogspot.com
    >
     
    Alvin Bruney [MVP], Feb 17, 2005
    #3
  4. Thank you both!
    So executing CLOSE on an SQLConnection is
    sufficient. No further need for a DISPOSE.
    Antonio

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:%...
    > Well, there really is more to it than that. By default, the connection
    > pooling is on. The default behavior of close flags the connection object
    > as reusable and returns it to the connection pool. After 60 seconds
    > (default timeout), the connection is truly closed. A closed connection may
    > then have the managed memory reclaimed. So either call has the same effect
    > underneath as rightly pointed out.
    >
    > --
    > Regards,
    > Alvin Bruney [Microsoft MVP ASP.NET]
    >
    > [Shameless Author plug]
    > The Microsoft Office Web Components Black Book with .NET
    > Now Available @ http://www.lulu.com/owc
    > ----------------------------------------------------------
    >
    >
    > "Tod Birdsall" <> wrote in message
    > news:...
    >> Hi Antonio,
    >>
    >> If you view the SqlConnection Dispose() method using a disassembler (I
    >> use .NET Reflector) you will see that all it does is check to see if
    >> the ConnectionState is open and if it is, it calls the Close() method.
    >>
    >> So, to answer your question, if you call Close() yourself, there is no
    >> need to call the Dispose() method.
    >>
    >> Tod Birdsall, MCP
    >> http://tod1d.blogspot.com
    >>

    >
    >
     
    Antonio Concepcion, Feb 17, 2005
    #4
    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. Bob
    Replies:
    6
    Views:
    10,659
    Jon Skeet [C# MVP]
    Feb 12, 2004
  2. =?Utf-8?B?QXNoYQ==?=

    dispose and nothing? whats the main difference?

    =?Utf-8?B?QXNoYQ==?=, Jul 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,837
    Scott Allen
    Jul 14, 2004
  3. Leon
    Replies:
    12
    Views:
    11,752
    luxmit85
    Feb 12, 2008
  4. Replies:
    0
    Views:
    472
  5. Chris

    MysqlConnection is not defined

    Chris, May 10, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    3,144
    Chris
    May 10, 2006
Loading...

Share This Page