how does Rails / Apache handle database connections?

Hi all,

I'm trying to figure out how Rails handles database connections. The business problem is: * My users have access to multiple, structurally identical schemas * So, for each request, Rails needs to be able to talk to a different schema * It's essential that users not pull data from the wrong schema

A couple more rules: * During the request, the schema used will not change * All the schemas can be accessed from one database server using one set of login credentials

The solution I'm contemplating is to execute a "use" statement for each request, so that all subsequent queries use the correct table.

My questions are: * How many database connections does each Rails process create? * Does this vary by adapter? (I'm using MS SQL Server) * Does apache pool database connections in any way? * Are database connections independent of Rails processes on apache?

Thanks! Daniel

Each rails process has a pool of connections (by default up to 5). I believe you can add a hook that runs after a connection is checked out (eg to set the current database). This layer of abstraction is independent of the various adapters. If you are using a multithreaded environment (of which the only one of note are the jruby ones, which your questions about apache imply you are not using) then you might have to be extra specially careful

Apache doesn't come into this at all.

Fred

This helped - thank you!