none
There is no SqlCommand.Close() method RRS feed

  • Question

  • HI

     

    SqlConnection have Close() method, but why SqlCommand have no Close() method?

    After UPDATE/DELETE/INSERT, there is no need to close the command(release command resources)?

     

    Is there have any resources to explain this.

     

    Best regards

     

    Chris

     

    Friday, May 23, 2008 6:40 AM

Answers

  • Command cannot have Close method, since it does not open any resources against database. It is the actual database connection that opens communication channel against database. But you still need to call Dispose method of SqlCommand to release resources properly.

    Friday, May 23, 2008 2:09 PM
    Moderator

All replies

  • SqlCommand has no close() method but if you use it to read data using SqlDataReader, then you will need to close instance of SqlDataReader class.
    Friday, May 23, 2008 7:29 AM
  • HI~

     

    And the resources(Database cursor, etc) will be release automatically?

     

    Best regards

     

    Chris

    Friday, May 23, 2008 8:19 AM
  • Which cursor? If you opened cursor in your sql script, you need to close it yourself.
    Friday, May 23, 2008 8:51 AM
  • please note that there is a .Dispose() method, that you need to implement

     

    Friday, May 23, 2008 1:00 PM
  • Command cannot have Close method, since it does not open any resources against database. It is the actual database connection that opens communication channel against database. But you still need to call Dispose method of SqlCommand to release resources properly.

    Friday, May 23, 2008 2:09 PM
    Moderator