Index: src/db.c
==================================================================
--- src/db.c
+++ src/db.c
@@ -882,10 +882,11 @@
   lsize = file_size(zDbName);
   if( lsize%1024!=0 || lsize<4096 ) return 0;
   db_open_or_attach(zDbName, "localdb", 0);
   zVFileDef = db_text(0, "SELECT sql FROM %s.sqlite_master"
                          " WHERE name=='vfile'", db_name("localdb"));
+  if( zVFileDef==0 ) return 0;
 
   /* If the "isexe" column is missing from the vfile table, then
   ** add it now.   This code added on 2010-03-06.  After all users have
   ** upgraded, this code can be safely deleted.
   */

Index: src/rebuild.c
==================================================================
--- src/rebuild.c
+++ src/rebuild.c
@@ -785,10 +785,12 @@
   int bVerily = find_option("verily",0,0)!=0;
   int bForce = find_option("force", "f", 0)!=0;
   int privateOnly = find_option("private",0,0)!=0;
   int bNeedRebuild = 0;
   db_find_and_open_repository(OPEN_ANY_SCHEMA, 2);
+  db_close(1);
+  db_open_repository(g.zRepositoryName);
   if( !bForce ){
     Blob ans;
     char cReply;
     blob_zero(&ans);
     prompt_user(

