Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.88
diff -u -Ftion -r1.88 bootstrap.inc
--- includes/bootstrap.inc	27 Feb 2006 13:46:01 -0000	1.88
+++ includes/bootstrap.inc	21 Mar 2006 00:02:00 -0000
@@ -589,8 +589,18 @@ function request_uri() {
  *   A link to associate with the message.
  */
 function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
-  global $user;
+  global $user, $db_url;            // bad OO, breaks DB encapsulation
+  // using $db_url is ugly because it breaks encapsulation of DB knowledge
+  if (isset($db_url['default'])) {
+    // in case alternate DB active when error
+    $actdb = db_set_active();
+  }
   db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, request_uri(), referer_uri(), $_SERVER['REMOTE_ADDR'], time());
+  // using $db_url is ugly because it breaks encapsulation of DB knowledge
+  if (isset($db_url['default'])) {
+    // in case alternate DB active when error
+    db_set_active($actdb);
+  }
 }
 
 /**
Index: includes/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.inc,v
retrieving revision 1.51
diff -u -Ftion -r1.51 database.inc
--- includes/database.inc	8 Mar 2006 15:13:20 -0000	1.51
+++ includes/database.inc	21 Mar 2006 00:02:00 -0000
@@ -100,6 +100,8 @@ function db_set_active($name = 'default'
   global $db_url, $db_type, $active_db;
   static $db_conns;
 
+  $previousdb = $active_db;
+
   if (!isset($db_conns[$name])) {
     // Initiate a new connection, using the named DB URL specified.
     if (is_array($db_url)) {
@@ -128,6 +130,7 @@ <p>For more help, see the <a href="http:
   }
   // Set the active connection.
   $active_db = $db_conns[$name];
+  return array_search($previousdb, $db_conns);
 }
 
 /**
