Why is Drupal displying missing core tables for an external DB? I'm using an external non Drupal DB to import some data from. The importing itself work, but I also get error like the ones below:

Uncaught exception thrown in shutdown function.

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table &amp;#039;lager_db.semaphore&amp;#039; doesn&amp;#039;t exist: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] =&amp;gt; 480420510502a64252605e0.49437518 ) in lock_release_all() (line 269 of /srv/www/002/drupal/includes/lock.inc).


Why is Drupal even looking to base tables in that Database and how do I get rid of these errors?

My DB setup in settings.php:

$databases['default']['default'] = array(
    'driver' =&gt; 'mysql',
    'database' =&gt; '002_db1',
    'username' =&gt; '002_u1',
    'password' =&gt; 'password',
    'host' =&gt; 'localhost',
    'prefix' =&gt; '',
    'collation' =&gt; 'utf8_swedish_ci',
  );

$databases['lager_db']['default'] = array(
    'driver' =&gt; 'mysql',
    'database' =&gt; 'lager_db',
    'username' =&gt; 'username',
    'password' =&gt; 'password',
    'host' =&gt; '192.168.60.130',
    'prefix' =&gt; '',
    'collation' =&gt; 'utf8_swedish_ci',
  );
If I had to guess you called db_set_active() in some code and forgot to switch back to your master drupal database, so "drupal" execution continued after you intended it to with the current database set as your alternate.

The lager_db probably has no semaphore table, but drupal's trying to call it anyways. You should switch back to drupal at the end of your custom code (or as necessary) with db_set_active(); it passes the 'default' parameter if none is given.