Do I have to close connections or does it makes no difference?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Do I have to close connections or does it makes no difference?

    Hello there,

    Am I right in thinking all connections to a database have to be closed
    and objects set to nothing? I'm finishing up a web site in ASP someone
    else started and most pages have this type of code:

    =========
    dim conn

    set conn = server.createobject("adodb.connection")

    conn.connectionstring ="Provider=Microsoft.Jet.OLEDB.4.0;Persist
    Security Info=False;Data Source=" &
    server.MapPath("../../../db/db_saad.mdb")

    conn.open

    set rs = conn.execute("SELECT * FROM X)

    ==========

    But those pages have none of these:

    conn.close
    set conn = nothing
    rs.close
    set rs = nothing


    Should I add this code?
    And what if there's a redirect before this code?
    zorro Guest

  2. Similar Questions and Discussions

    1. Connections don't close in ie 6.0
      At our company we have built a video/chat application with multiple rooms and a lobby using FMS2. The application runs fine in most browsers but...
    2. #39457 [NEW]: Multiple invoked OO connections never close
      From: josh at mykoala dot com Operating system: OS X 10.4.8 PHP version: 5.2.0 PHP Bug Type: MySQLi related Bug description:...
    3. close my project that is in a browser window (close this window)
      How can I do this with a button? What do I have to put into button?
    4. close ALL connections
      is there a way to close all open database connections without referring to each connection by name across an entire server? mark
    5. perlcc makes it big
      I'm running perl 5.8.0 on linux. I wrote a very simple program: #!/usr/bin/perl print "test"; that's it! and ran perlcc. it gave me an...
  3. #2

    Default Re: Do I have to close connections or does it makes no difference?

    Hi...

    It's considered very good coding practice to close all connections as soon
    as you no longer need them.

    Also, set all object references to nothing as soon as you are done with them
    too.

    All object references however are destroyed when the page has finished
    execution.

    Hope this helps.
    --
    Rob Collyer - [url]www.webforumz.com[/url]
    Web design and development forums for Free help, advice,
    tips, and website critique by professional designers and developers.



    "zorro" <myahact@yahoo.ca> wrote in message
    news:1baa8f0d.0407181013.614f4f66@posting.google.c om...
    > Hello there,
    >
    > Am I right in thinking all connections to a database have to be closed
    > and objects set to nothing? I'm finishing up a web site in ASP someone
    > else started and most pages have this type of code:
    >
    > =========
    > dim conn
    >
    > set conn = server.createobject("adodb.connection")
    >
    > conn.connectionstring ="Provider=Microsoft.Jet.OLEDB.4.0;Persist
    > Security Info=False;Data Source=" &
    > server.MapPath("../../../db/db_saad.mdb")
    >
    > conn.open
    >
    > set rs = conn.execute("SELECT * FROM X)
    >
    > ==========
    >
    > But those pages have none of these:
    >
    > conn.close
    > set conn = nothing
    > rs.close
    > set rs = nothing
    >
    >
    > Should I add this code?
    > And what if there's a redirect before this code?

    Rob Collyer Guest

  4. #3

    Default Re: Do I have to close connections or does it makes no difference?

    On 18 Jul 2004 11:13:04 -0700, [email]myahact@yahoo.ca[/email] (zorro) wrote:
    >Hello there,
    >
    >Am I right in thinking all connections to a database have to be closed
    >and objects set to nothing?
    Have to be? No. Should be? Definite yes.

    Connections close and objects are destroyed when the page closes, but
    you have no control over that event happening so close connections and
    destroy objects as soon as you no longer need them.
    >I'm finishing up a web site in ASP someone
    >else started and most pages have this type of code:
    >
    >=========
    >dim conn
    >
    >set conn = server.createobject("adodb.connection")
    >
    >conn.connectionstring ="Provider=Microsoft.Jet.OLEDB.4.0;Persist
    >Security Info=False;Data Source=" &
    >server.MapPath("../../../db/db_saad.mdb")
    >
    >conn.open
    >
    >set rs = conn.execute("SELECT * FROM X)
    >
    >==========
    >
    >But those pages have none of these:
    >
    >conn.close
    >set conn = nothing
    >rs.close
    >set rs = nothing
    >
    >
    >Should I add this code?
    Yes
    >And what if there's a redirect before this code?
    Redirect after you close. Call it as a sub, or drop through to it
    with a redirect after.

    Jeff
    Jeff Cochran Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139