ASP (not Asp.Net) database best practice?

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

  1. #1

    Default ASP (not Asp.Net) database best practice?

    Will the object variables of

    Connection, - Server.CreateObject("ADODB.Connection")
    Recordset - Server.CreateObject("ADODB.Recordset")
    and Command - Server.CreateObject("ADODB.Command")

    be automatically released after the asp page finished running or error
    exception (e.g. the database get down)?

    I've the following function:
    function openRS(conn, strCmd, item)
    {
    var cmd = Server.CreateObject("ADODB.Command")
    var rs = Server.CreateObject("ADODB.Recordset")

    rs.CursorType = adOpenForwardOnly
    rs.LockType = adLockReadOnly

    cmd.ActiveConnection = conn
    cmd.CommandText = strCmd
    cmd.CommandType = adCmdStoredProc

    // Parameter pItem
    var param = cmd.CreateParameter("@pItem",adVarChar,adParamInpu t,50,"")
    cmd.Parameters.Append(param)
    cmd.Parameters("@pItem") = item

    rs.Open(cmd)

    return rs
    }

    For example, if I never do "cmd = null" right after rs.Open(cmd), can it
    causes problem? or ASP will automatically release it after run or error
    exception?
    nick Guest

  2. Similar Questions and Discussions

    1. best practice / tips
      What are the best practices for setting up a 3d game? (stripping the programming for the most part) is it best to make one w3d with everything...
    2. Best practice for login screen using database
      I have an c# as.net app that check if the user exist in a USERS table, that part is ok but now I need to pass the user ID no the next page beacuse...
    3. Best practice in postgres
      Hi All, I'm new to postgres, so I need your help. We are in the process of migrating from oracle to postgres. DB size is about 400gb. My...
    4. WS-Security Best Practice?
      I'm new to Webservices, but nonetheless have taken the leap! I have a ws I'm writing that will be used in a subscription. Nothing huge or...
    5. best practice question regarding AspState database for sessions
      Quick question regarding best practices for using the AspState database for storing session variables in .NET web applications. I know I need to...
  3. #2

    Default Re: ASP (not Asp.Net) database best practice?

    nick wrote:
    > Will the object variables of
    >
    > Connection, - Server.CreateObject("ADODB.Connection")
    > Recordset - Server.CreateObject("ADODB.Recordset")
    > and Command - Server.CreateObject("ADODB.Command")
    >
    > be automatically released after the asp page finished running or error
    > exception (e.g. the database get down)?
    >
    See
    [url]http://blogs.msdn.com/ericlippert/archive/2003/09/17/53038.aspx[/url]
    and
    [url]http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx[/url]


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  4. #3

    Default Re: ASP (not Asp.Net) database best practice?

    Bob Barrows [MVP] wrote:
    > nick wrote:
    >
    >>Will the object variables of
    >>
    >>Connection, - Server.CreateObject("ADODB.Connection")
    >>Recordset - Server.CreateObject("ADODB.Recordset")
    >>and Command - Server.CreateObject("ADODB.Command")
    >>
    >>be automatically released after the asp page finished running or error
    >>exception (e.g. the database get down)?
    >>
    >
    >
    > See
    > [url]http://blogs.msdn.com/ericlippert/archive/2003/09/17/53038.aspx[/url]
    > and
    > [url]http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx[/url]
    >
    >
    Thanks.

    So according to the links. I needn't do
    cmd = null
    in my example.

    And I even needn't worry about using Jscript's
    try {... database }
    Finally { code to close connection, release database objects....}
    to handle exceptions of database?
    nick Guest

  5. #4

    Default Re: ASP (not Asp.Net) database best practice?

    nick wrote:
    > Bob Barrows [MVP] wrote:
    >
    >> nick wrote:
    >>
    >>> Will the object variables of
    >>>
    >>> Connection, - Server.CreateObject("ADODB.Connection")
    >>> Recordset - Server.CreateObject("ADODB.Recordset")
    >>> and Command - Server.CreateObject("ADODB.Command")
    >>>
    >>> be automatically released after the asp page finished running or
    >>> error exception (e.g. the database get down)?
    >>>
    >>
    >>
    >> See
    >> [url]http://blogs.msdn.com/ericlippert/archive/2003/09/17/53038.aspx[/url]
    >> and
    >> [url]http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx[/url]
    >>
    >>
    >
    > Thanks.
    >
    > So according to the links. I needn't do
    > cmd = null
    > in my example.
    It can't hurt, but is probably unnecessary.
    >
    > And I even needn't worry about using Jscript's
    > try {... database }
    > Finally { code to close connection, release database objects....}
    > to handle exceptions of database?
    You should always explicitly close and destroy your ADO recordsets and
    connections (make sure you digest the part about circular references - child
    objects should be cleaned before parent objects. Failure to adhere to this
    can lead to memory leaks that can crash IIS) as early as possible to allow
    the connections to go back into the connection pool to be used by other
    threads. I would not wait until a Finally block to close them if there will
    be a large amount of code to run before the Finally block is reached. One of
    the main points made in the second link is the need/desirability to free
    expensive resources as early as possible. This consideration should not be
    ignored.

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] 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