Index: src/db.c
==================================================================
--- src/db.c
+++ src/db.c
@@ -765,11 +765,19 @@
 ** case, invoke this routine with useAttach as 1.
 */
 void db_open_config(int useAttach){
   char *zDbName;
   const char *zHome;
-  if( g.configOpen ) return;
+  if( g.configOpen ){
+    if( useAttach==g.useAttach ) return;
+    if( g.useAttach ){
+      db_detach("configdb");
+    }else if( g.dbConfig ){
+      sqlite3_close(g.dbConfig);
+      g.dbConfig = 0;
+    }
+  }
 #if defined(_WIN32)
   zHome = fossil_getenv("LOCALAPPDATA");
   if( zHome==0 ){
     zHome = fossil_getenv("APPDATA");
     if( zHome==0 ){