locked
Is db.close() required? RRS feed

  • Question

  • User-1327394822 posted
    In a webmatrix page, when you perform an operation at the start of the page, is it required to close the database connection?
    Friday, April 8, 2016 6:43 AM

Answers

All replies

  • User541108374 posted

    Hi,

    the mantra of connecting to databases is: open as late as possible, close as early as possible. Best way is to make use of a using() statement so the resources are cleaned up afer usage.

    Grz, Kris.

    Friday, April 8, 2016 7:51 AM
  • User379720387 posted

    Nope.  Happens by itself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 8, 2016 12:56 PM
  • User-821857111 posted

    As wavemaster said, no it is not necessary to call db.Close. The Web Pages runtime closes it for you. pranavkm from the ASP.NET team explains it here: https://forums.asp.net/p/1649902/4420872.aspx?Re+closing+a+database+

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 8, 2016 8:58 PM