I have been asked a couple of times, why does ad_conn return an error when there is no connection, and if this is the case, why doesn't it state so on a prime position in the documentation. New people expect (and this does include me, though I know from working for years with OpenACS that it does not work that way) that, if there is no connection, than the value should be empty.
I personally agree and to my knowledge ns_conn usually does not return empty values when there is a connection, but as this would break backward compatability I think we are stuck with it.
Don pointed out the following:
""ns_conn isconnected returns 1 if you're in a connection thread, and you are therefore allowed to make calls to ns_conn. It returns 0 if you're not in a connection thread (such as when you're in a scheduled procedure) and you are not allowed to make calls to ns_conn."
You're supposed to check if the connection exists (you can use [ad_conn isconnected] for consistency) before calling ns_conn, and if you don't, and isconnected is 0, you get an error."