Index: dbutil.cpp
===================================================================
--- dbutil.cpp	(revision 17978)
+++ dbutil.cpp	(working copy)
@@ -205,6 +205,28 @@
         return true;
     }
 
+    // HACK: If an upgrade failed, the schemalock table may still be locked.
+    //       Both backup commands currently try to lock all tables,
+    //       and thus will silently sit waiting forever.
+    if (isSchemaLocked())
+    {
+        MythTimer elapsedTimer; 
+        elapsedTimer.start(); 
+
+        do
+        {
+            VERBOSE(VB_IMPORTANT, "Database schema are locked. Waiting...");
+            sleep(1);
+        }
+        while (isSchemaLocked() && (elapsedTimer.elapsed() < 10000));
+
+        if (isSchemaLocked())
+        {
+            VERBOSE(VB_IMPORTANT, "Still locked. Cannot backup/upgrade DB");
+            return false;
+        }
+    }
+
     QString backupScript = GetShareDir() + "mythconverg_backup.pl";
     backupScript = gContext->GetSetting("DatabaseBackupScript", backupScript);
 
@@ -680,6 +702,19 @@
     return count;
 }
 
+bool DBUtil::IsTableLocked(const QString &name)
+{
+    DatabaseParams dbParams = gContext->GetDatabaseParams();
+    MSqlQuery      query(MSqlQuery::InitCon());
+
+    query.exec("SHOW OPEN TABLES FROM " + dbParams.dbName);
+    while (query.next())
+        if (query.value(1).toString() == name && query.value(2).toInt() > 0)
+            return true;
+
+    return false;
+}
+
 /**
  * \brief Try to get a lock on the table schemalock.
  *
@@ -713,4 +748,9 @@
     query.exec("UNLOCK TABLES;");  // Should this _just_ unlock schemalock?
 }
 
+bool DBUtil::isSchemaLocked(void)
+{
+    return IsTableLocked("schemalock");
+}
+
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: dbutil.h
===================================================================
--- dbutil.h	(revision 17978)
+++ dbutil.h	(working copy)
@@ -34,11 +34,12 @@
     static bool IsNewDatabase(void);
     static bool IsBackupInProgress(void);
     static int  CountClients(void);
+    static bool IsTableLocked(const QString &);
 
     static bool lockSchema(MSqlQuery &);
     static void unlockSchema(MSqlQuery &);
+    static bool isSchemaLocked(void);
 
-
     static const int kUnknownVersionNumber;
 
   protected:
Index: schemawizard.cpp
===================================================================
--- schemawizard.cpp	(revision 17978)
+++ schemawizard.cpp	(working copy)
@@ -105,7 +105,6 @@
         VERBOSE(VB_IMPORTANT, "Database schema is old."
                               " Waiting to see if DB is being upgraded."); 
 
-        MSqlQuery query(MSqlQuery::InitCon());
         bool      backupRunning  = false; 
         bool      upgradeRunning = false; 
 
@@ -127,7 +126,7 @@
                 continue;
             } 
 
-            if (!lockSchema(query))
+            if (isSchemaLocked())
             {
                 VERBOSE(VB_IMPORTANT,
                         "Waiting for Database Upgrade to complete."); 
@@ -140,7 +139,6 @@
             }
 
             Compare(); 
-            unlockSchema(query);
 
             if (m_expertMode)  // Experts don't like to wait around :-)
                 break;
@@ -187,10 +185,12 @@
 {
     bool     connections;   // Are (other) FE/BEs connected?
     bool     gui;           // Was gContext Init'ed gui=true?
+    bool     locked;        // Database schemalock
     bool     upgradable;    // Can/should we upgrade?
     bool     validDBMS;     // Do we measure up to minDBMS* ?
     QString  warnOldDBMS;
     QString  warnOtherCl;
+    QString  warnSchLock;
 
 
 
@@ -205,11 +205,13 @@
 
     connections = CountClients() > 1;
     gui         = GetMythUI()->IsScreenSetup();
+    locked      = isSchemaLocked();
     validDBMS   = (minDBMSmajor == 0)   // If the caller provided no version,
                   ? true                // the upgrade code can't be fussy!
                   : CompareDBMSVersion(minDBMSmajor,
                                        minDBMSminor, minDBMSpoint) >= 0;
     upgradable  = validDBMS && (versionsBehind > 0)
+                            && !locked
                             && (upgradeAllowed || m_expertMode);
 
 
@@ -223,9 +225,12 @@
                          "  You seem to be running MySQL version %5.")
                       .arg(name).arg(minDBMSmajor).arg(minDBMSminor)
                       .arg(minDBMSpoint).arg(GetDBMSVersion());
+    if (locked)
+        warnSchLock = tr("Error: It appears that an earlier schema upgrade"
+                         " has crashed. (TABLE schemlock is locked) "
+                         " Please check all backend logs.");
 
 
-
     //
     // 1. Deal with the trivial cases (No user prompting required)
     //
@@ -291,6 +296,11 @@
                               " but that may cause problems.");
         }
     }
+    else if (locked)
+    {
+        message = warnSchLock;
+        returnValue = MYTH_SCHEMA_ERROR;
+    }
     else if (!validDBMS)
     {
         message = warnOldDBMS;
