How to create a Webform pre-build option list via a query to an external database?
I changed this:

function webform_pre_build_list_db() {
db_set_active('external_db');
return db_query('SELECT id, name FROM table')-&gt;fetchAllKeyed();
db_set_active('default');
}


to this

function webform_pre_build_list_db() {
  db_set_active('external_db');
  $options = db_query('SELECT id, name FROM table')-&gt;fetchAllKeyed();
  db_set_active('default');
  return $options;
}


And it's working!

(Explanation: return immediately ends the execution of a function, in this case before db_set_active() could be called.) 

Thanks to Nevets