Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Do we need to call dbCommand.Dispose() ?

Do we need to call dbCommand.Dispose() ?

Scheduled Pinned Locked Moved C#
questiondatabasehelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    s o v a n n
    wrote on last edited by
    #1

    Hello ! I have a question about DB specifications : Do we have to call IDbCommand.Dispose ? What does IDbCommand.Dispose mean? We have problem doing this : IDbConnction pipe = new OleDbConnection(connString); IDbCommand command = pipe.CreateCommand(); command.QueryString = "select ..."; IDataReader reader = command.ExecuteReader(); **command.Dispose();** reader.Close(); pipe.Close(); The problem get solved if we don't do IDbCommand.Dispose Your comments would be very helpful. Thanks. Sovann

    N 1 Reply Last reply
    0
    • S s o v a n n

      Hello ! I have a question about DB specifications : Do we have to call IDbCommand.Dispose ? What does IDbCommand.Dispose mean? We have problem doing this : IDbConnction pipe = new OleDbConnection(connString); IDbCommand command = pipe.CreateCommand(); command.QueryString = "select ..."; IDataReader reader = command.ExecuteReader(); **command.Dispose();** reader.Close(); pipe.Close(); The problem get solved if we don't do IDbCommand.Dispose Your comments would be very helpful. Thanks. Sovann

      N Offline
      N Offline
      Navi15
      wrote on last edited by
      #2

      You cannot Dispose Command Object after ExecuteReader Method, the datareader object maintains the connection to the database as it will not pull all data at once, and it will pull data record by record. So dispose the command object after getting all the data.

      Naveen G MCSD.Net

      S 1 Reply Last reply
      0
      • N Navi15

        You cannot Dispose Command Object after ExecuteReader Method, the datareader object maintains the connection to the database as it will not pull all data at once, and it will pull data record by record. So dispose the command object after getting all the data.

        Naveen G MCSD.Net

        S Offline
        S Offline
        s o v a n n
        wrote on last edited by
        #3

        Thank you. Anyway, do we have to call IDbCommand.Dispose ?

        S 1 Reply Last reply
        0
        • S s o v a n n

          Thank you. Anyway, do we have to call IDbCommand.Dispose ?

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          Whenever a class exposes a Dispose method you should definitely call it as it frees resources immediatly. You can take advantage of the using statement that automatically calls Dispose on an object when execution leaves its scope. Simple example taken from MSDN.

          using (Font font1 = new Font("Arial", 10.0f))
          {
          //use font1 object
          }


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          S 1 Reply Last reply
          0
          • S Stefan Troschuetz

            Whenever a class exposes a Dispose method you should definitely call it as it frees resources immediatly. You can take advantage of the using statement that automatically calls Dispose on an object when execution leaves its scope. Simple example taken from MSDN.

            using (Font font1 = new Font("Arial", 10.0f))
            {
            //use font1 object
            }


            "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

            www.troschuetz.de

            S Offline
            S Offline
            s o v a n n
            wrote on last edited by
            #5

            Thank you. Your comment has been very helpful :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups