in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

SQLiteDataReader with CommandBehavior.CloseConnection should call Dispose, not Close, on the connection

Last post 04-30-2008 6:21 PM by Robert Simpson. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-30-2008 12:15 PM

    • Sam_
    • Top 10 Contributor
    • Joined on 02-14-2007
    • Washington DC
    • Posts 86

    SQLiteDataReader with CommandBehavior.CloseConnection should call Dispose, not Close, on the connection

    In SQLiteDataReader.Close(), these two lines of code:

     

            if ((_commandBehavior & CommandBehavior.CloseConnection) != 0 && _command.Connection != null)
              _command.Connection.Close();
     

    should read

     

            if ((_commandBehavior & CommandBehavior.CloseConnection) != 0 && _command.Connection != null)
              _command.Connection.Dispose();
     

    So the connection gets closed and the finalizer is suppressed.   We did some investigation into disposable objects that were not being properly disposed in our application and came across this.  

    Thanks,

    Sam

    We're hiring! B-Line Medical is seeking .NET Developers for exciting positions in medical product development in MD/DC. Work with a variety of technologies in a relaxed team environment. See ads on http://careerbuilder.com.
  • 04-30-2008 3:55 PM In reply to

    • Nate
    • Top 10 Contributor
    • Joined on 08-28-2005
    • Fort Collins, CO
    • Posts 68

    Re: SQLiteDataReader with CommandBehavior.CloseConnection should call Dispose, not Close, on the connection

    If the expected behavior is to close a connection, why would you dispose of it? I expect that when a connection is closed, it is able to be reopened, not disposed of.

    Perhaps I misunderstood what you are saying?

  • 04-30-2008 6:21 PM In reply to

    Re: SQLiteDataReader with CommandBehavior.CloseConnection should call Dispose, not Close, on the connection

    Agreed.  IMO the function is correct as coded.  CloseConnection is documented to close a connection, not dispose of it entirely.

     

Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems