Forum OpenACS Q&A: Response to passing db handle to proc versus opening handle inside proc...

You can design the proc to work with or without a handle passed to it (something we resort to a lot where I work):

proc foo { some_variable { db "" } } {

    if {[string compare $db ""] == 0} {
        set db [ns_db gethandle subquery]
        set release 1
    } else {
        set release 0
    }

    some more code

    if {$release} {
        ns_db releasehandle $db
    }
}

This is useful because sometimes you already have a handle when you call the proc, but if you don't it's nice to have the proc handle that. I believe ACS 4 makes this irrelevant, because you use a utility that gets and releases the handle for all calls to the database.