title: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to open database with message 'not an error'.'
body: <p>I am making an app with many database operations. Since SQLite caches data, in my applicationDidReceiveMemoryWarning method, I am closing the database and opening it again to delete the cached data.</p>
  
  <p>When the do this, I get this error</p>
  
  <blockquote>
    <p>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to open database with message 'not an error'.'</p>
  </blockquote>
  
  <p>Here's the code I am using to close the database and open again where database is of type sqlite3*
       [MySQLInter finalizeStatements];</p>
  
  <pre><code> if(sqlite3_close(database) == SQLITE_OK){
  
  //open again
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  
  NSString *documentsDirectory = [paths objectAtIndex:0];
  
  NSString *path = [documentsDirectory stringByAppendingPathComponent:@"mydb.sql"];
  
  
      if(sqlite3_open([path UTF8String], &amp;database) != SQLITE_OK){
  
           NSAssert1(0, @"Error: failed to open database with message '%s'.", sqlite3_errmsg(database));
  
  }
  
   }
  
   else{
  
  NSAssert1(0, @"Error: failed to close database on memwarning with message '%s'.", sqlite3_errmsg(database));
  
   }
  </code></pre>
  
  <p>How to avoid this?</p>