Forum OpenACS Development: Re: ns_db gethandle gives error 'could not allocate 1 handle from pool "pool1"' Naviserver on Windows

just a short reply (i am very short on time). An OpenACS application developer should never do a [ns_db gethandle] manually, since this bypasses the handle-managemement form OpenACS, using multiple pools. A application developer should use instead the db* interface, or maybe "db_with_handle".

From every pool, every request gets just one handle (and might put it back manually or at the end of the request). The handle information is managed/reused in OpenACS via global tcl variables such that a complex page with e.g. 100 sql requests needs just a single "gethandle" request.

The question whether or not a manual "ns_db gethandle" returns a value or not boils down to the question whether or not the request has already requested a handle. On OpenACS.org, the command

 set db [ns_db gethandle]
succeeds, but
 set db1 [ns_db gethandle]
 set db2 [ns_db gethandle]
fails. It seems, that in your instance, probably the templates issue already requests from pool1, therefore the request from pool1 fails but the request for pool2 succeeds. This is the same behavior as on Linux or Mac OS.

Hope this helps.

Hi Gustaf

thanks very much for replying when you are under so much pressure - I do appreciate it.

I understand the situation much more now, and yes it makes sense that the templating system is getting the first handle. In earlier versions of OpenACS under AOLserver, it didn't seem to cause a problem. Unfortunately we have some legacy code that does call ns_db gethandle, so I'll investigate what's involved in re-writing that using db_with_handle or similar.

all the best
Brian

I guess, it is not the templating system that get's the handle, but the master template might call some SQL function, that causes the handle allocation. concerning "ns_db gethandle": I do not remember any changes in OpenACS (or AOLserver/NaviServer) in these regards since i started to use OpenACS, which was more than 10 years ago... but i know there is much code out there, which predates this and often runs quite well.