Professional Web Applications Themes

Question about setting a Conn = nothing - ASP

We have a component that takes in an ADO record set and returns a dictionary object populated with the same data. My question resolves around this practise which I see everywhere: set conn = nothing set dbRS = nothing But the connection remains open till you explicitly close it right? Is it that this is anticipating connection pooling and so you want to clear out that thread in the pool before it services another request? It looks like your specifically creating a null pointer? It's everywhere in ASP code but nowhere did I find an explanation of why you need ...

  1. #1

    Default Question about setting a Conn = nothing

    We have a component that takes in an ADO record set and returns a
    dictionary object populated with the same data. My question resolves
    around this practise which I see everywhere:

    set conn = nothing
    set dbRS = nothing


    But the connection remains open till you explicitly close it right? Is
    it that this is anticipating connection pooling and so you want to
    clear out that thread in the pool before it services another request?
    It looks like your specifically creating a null pointer? It's
    everywhere in ASP code but nowhere did I find an explanation of why
    you need to do this.

    dba Guest

  2. #2

    Default Re: Question about setting a Conn = nothing


    Hi,

    Whenever you are writing code in any form (C, VB or ASP) it is good practise
    to clean up after yourself instead of assuming the reletive engine will do
    this for you. In the case of ASP and when referencing a database it's both
    important to close the connection and then clear the data in memory once
    you've finished with it. Along with performance gains (your web
    applications using less runtime memory) it will also stop you running into
    problems later such as trying to reuse an object that is bound to something
    else for example.

    So to create a nice block you would open your connection:

    set oDBConn = server.createobject("adodb.connection")
    oDBConn.Open sDBConnectString
    oDBConn.CursorLocation=adUseClient
    set oDBCmd = server.createobject("adodb.command")

    Then you would user the connection

    oDBCmd.ActiveConnection = oDBConn
    oDBCmd.CommandText = "sp_StoredProc1"
    oDBCmd.CommandType = adCmdStoredProc
    oDBCmd.Parameters.Append oDBCmd.CreateParameter("PARAM1", adInteger,
    adParamInput, 4, iVal1)
    oDBCmd.Parameters.Append oDBCmd.CreateParameter("PARAM2", adInteger,
    adParamInput, 4, iVal2)
    oDBCmd.Parameters.Append oDBCmd.CreateParameter("PARAM3", adInteger,
    adParamInput, 4, iVal3)
    set oDBRSData = server.createobject("adodb.recordset")
    set oDBRSData = oDBCmd.Execute()
    set oDBCmd = Nothing

    Then you would use the data and then clean up

    oDBRSData.Close()
    set oDBRSData = Nothing

    oDBConn.Close()
    set oDBConn = Nothing

    It's important that you close the recordset or connection before setting the
    pointer to nothing, otherwise you in essense loose the pointer to the
    recordset and data and can't access (or close) it then.

    Hope this helps,

    Jon

    [url]www.insidetheregistry.com[/url]

    --

    "dba" <bryanmurtha> wrote in message
    news:4697b6de-7bb2-4c27-b782-83a91e187ddea12g2000yqm.googlegroups.com...
    > We have a component that takes in an ADO record set and returns a
    > dictionary object populated with the same data. My question resolves
    > around this practise which I see everywhere:
    >
    > set conn = nothing
    > set dbRS = nothing
    >
    >
    > But the connection remains open till you explicitly close it right? Is
    > it that this is anticipating connection pooling and so you want to
    > clear out that thread in the pool before it services another request?
    > It looks like your specifically creating a null pointer? It's
    > everywhere in ASP code but nowhere did I find an explanation of why
    > you need to do this.
    >
    Jon Wallace Guest

Similar Threads

  1. Basic Design Qs - XML Conn, Dataset, Buttons
    By Crafter_guy in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: February 3rd, 06:45 PM
  2. trouble with db conn dsn
    By RJweb in forum Coldfusion Database Access
    Replies: 1
    Last Post: April 4th, 09:45 PM
  3. conn.open problem on client, not on server
    By Tim. D in forum ASP Database
    Replies: 5
    Last Post: August 5th, 08:35 AM
  4. Profiler Question (Setting Filters)
    By Amos Soma in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 3rd, 04:59 PM
  5. reading sqldatareader after conn.close()
    By Ante Perkovic in forum ASP.NET General
    Replies: 0
    Last Post: July 2nd, 10:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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