Database objects scope

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

  1. #1

    Default Re: Database objects scope

    What will go wrong? I ran the following page for 36 hours. It didn't
    have any affect on the memory used. It looks like the ADO-COM objects
    get released as they should when going out of scope. It is virtually
    impossible to dereference all the ADO objects, since there are
    Response.End and Response.Redirect's etc.

    Christiaan.


    <%
    option explicit
    dim rs,sql,conn
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Open "Driver={SQL
    Server};Server=.;Uid=SA;Pwd=;Database=northwind"
    set rs=conn.Execute("select * from employees")
    %>
    <html>
    <body>
    <%
    dim i
    do until rs.eof
    Response.Write rs("employeeid") & " " & rs("Firstname") & " " &
    rs("LastName") & "<br>"
    i=i+1
    if i>5 then exit do
    rs.MoveNext
    loop
    Response.Write now() & "<br>"
    %>
    <script>
    location.reload()
    </script>
    </body>
    </html>



    "Kris Eiben" <eibenkthisisforspammers@yahoo.com> wrote in message news:<O#GOfPrUDHA.3312@tk2msftngp13.phx.gbl>...
    > OK, so call it a bug in the garbage collection. But your customer won't
    > take that as an excuse when your pages stop working. So, yes, there is
    > a lot of "use" in closing and destroying all your objects.
    > More info here:
    > [url]http://www.aspfaq.com/show.asp?id=2435[/url]
    > [url]http://www.aspfaq.com/show.asp?id=2227[/url]
    >
    > "Christiaan Nijdam" <acnijdam_n0spam@yahoo.com> wrote in message
    > news:83f4b79a.0307250200.4c899f8d@posting.google.c om...
    > > Hi,
    > > Is it any use to close and dereference a used recordset and/or
    > > connection at the end of an ASP page just before it goes out of scope?
    > > <%
    > > dim conn,rs
    > > set conn=Server.CreateObject("ADODB.Connection")
    > > conn.Open "bla"
    > > set rs=connection.Execute("select * from tblSomeTable")
    > > 'Can the following lines can be left out?
    > > rs.Close()
    > > Set rs=Nothing
    > > conn.Close
    > > set conn=nothing
    > > %>
    > > Some say the recordset and/or connection will exist beyond the page
    > > scope and will never be released. Is there any explicit documentation
    > > from Microsoft about this subject? If closing and dereferencing is
    > > really necessary wouldn't that be a bug in ASP/ADO?
    Christiaan Nijdam Guest

  2. Similar Questions and Discussions

    1. #40604 [NEW]: Objects disappear from the global scope
      From: dagdamor at simps dot ru Operating system: Windows PHP version: 5.2.1 PHP Bug Type: Class/Object related Bug...
    2. #39719 [NEW]: Lost of scope in objects
      From: daxohara at gmail dot com Operating system: debian etch/ubuntu edgy-elf PHP version: 5.2.0 PHP Bug Type: Class/Object...
    3. Scope of variables defined in text objects
      What's the scope of a variable assigned to a text object? Its own timeline, _root, or what?
    4. Readonly Database Objects??
      I have a problem that I have caused more than once in the last 2 weeks I have a working Access database that is being queried and updated via web...
    5. Problem with sessions (in global scope vs class scope)
      Hello, i'me having a wierd problems with sessions. PHP 4.3.3, Register globals is on, and the sessions module is installed. if i have a page like...
  3. #2

    Default Re: Database objects scope

    Christiaan Nijdam wrote:
    > What will go wrong? I ran the following page for 36 hours. It didn't
    > have any affect on the memory used.
    This code may be all right. You are going through the entire set of records
    before ending the script. That increases the likelihood that the ADO objects
    will be released when they go out of scope. But ... I would not count on it!

    Where you can get into trouble is if you fail to retrieve the last record in
    a recordset for some reason (this could be deliberate). The recordset may
    fail to automatically close in this scenario.

    Bottom line: do not depend on your simple test here. When multiple users and
    threads intrude, the results may be quite different. There have been many
    cases reported in these newsgroups where IIS would die after a day or two,
    with the problem going away when ADO objects were explicitly dereferenced.

    > It looks like the ADO-COM objects
    > get released as they should when going out of scope. It is virtually
    > impossible to dereference all the ADO objects, since there are
    > Response.End and Response.Redirect's etc.
    No it isn't. It is very far from impossible. It may be difficult due to the
    number of redirects, etc, but it is certainly not impossible.
    Simply dereference the objects before the response.end or response.redirect
    statement.

    You can use this as a good opportunity to cut down on the number of
    redirects and ends ...

    Bob Barrows



    Bob Barrows Guest

  4. #3

    Default Re: Database objects scope

    Ok, it is clear that it is not so clear what will happen. Knowing the
    mentioned reports, better be safe, although it is a lot of work. I
    hoped that maybe there is an advise with an explanation from the
    builders Microsoft....


    Thanks,
    Christiaan.


    "Bob Barrows" <reb_01501@yahoo.com> wrote in message news:<#8#AVRQVDHA.3220@tk2msftngp13.phx.gbl>...
    > Christiaan Nijdam wrote:
    > > What will go wrong? I ran the following page for 36 hours. It didn't
    > > have any affect on the memory used.
    >
    > This code may be all right. You are going through the entire set of records
    > before ending the script. That increases the likelihood that the ADO objects
    > will be released when they go out of scope. But ... I would not count on it!
    >
    > Where you can get into trouble is if you fail to retrieve the last record in
    > a recordset for some reason (this could be deliberate). The recordset may
    > fail to automatically close in this scenario.
    This is what i tested. Some records are skipped by counting in i...
    >
    > Bottom line: do not depend on your simple test here. When multiple users and
    > threads intrude, the results may be quite different. There have been many
    > cases reported in these newsgroups where IIS would die after a day or two,
    > with the problem going away when ADO objects were explicitly dereferenced.
    >
    >
    > > It looks like the ADO-COM objects
    > > get released as they should when going out of scope. It is virtually
    > > impossible to dereference all the ADO objects, since there are
    > > Response.End and Response.Redirect's etc.
    >
    > No it isn't. It is very far from impossible. It may be difficult due to the
    > number of redirects, etc, but it is certainly not impossible.
    > Simply dereference the objects before the response.end or response.redirect
    > statement.
    >
    > You can use this as a good opportunity to cut down on the number of
    > redirects and ends ...
    >
    > Bob Barrows
    Christiaan Nijdam 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