title: +metadataForPersistentStoreOfType failure with NSSQLiteErrorDomain 14
body: <p>I need to find the version of the model used in an existing persistent store so I can do a little post-processing after an automatic lightweight migration.</p>
  
  <p>We've got a few devices in a state where we are unable to get the metadata for their persistent stores.</p>
  
  <p>When we initialize the CoreData stack, we use NSPersistentStoreCoordinator's +metadataForPersistentStoreOfType:URL:error: method to get the metadata for the existing persistent store.  Then we check if it's metadata is compatible with the metadata from the current object model to decide if we need to do a migration.  We also pull the model versions from these two sets of metadata--so after the automatic lightweight migration we can do some simple post-processing based on the model versions.</p>
  
  <p>The problem is that +metadataForPersistentStoreOfType:URL:error: is failing and returning nil on some devices.  The error indicates NSSQLiteErrorDomain 14 and "I/O error for database at ".  If I turn on SQLite debugging ("-com.apple.CoreData.SQLDebug 1") it doesn't produce much useful info:</p>
  
  <pre><code>CoreData: annotation: Connecting to sqlite database file at "/var/mobile/Applications/65838AB8-2DE4-4B1E-9837-FD252104448B/Library/slide_deck_database_1/StoreContent/persistentStore"
  CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA
  CoreData: annotation: Disconnecting from sqlite database due to an error.
  CoreData: error: (14) I/O error for database at /var/mobile/Applications/65838AB8-2DE4-4B1E-9837-FD252104448B/Library/slide_deck_database_1/StoreContent/persistentStore.  SQLite error code:14, 'unable to open database file'
  CoreData: annotation: Disconnecting from sqlite database.
  metadataForPersistentStoreOfType failed with error: The operation couldn’t be completed. (Cocoa error 256.) (userInfo: {
      NSSQLiteErrorDomain = 14;
      NSUnderlyingException = "I/O error for database at /var/mobile/Applications/65838AB8-2DE4-4B1E-9837-FD252104448B/Library/slide_deck_database_1/StoreContent/persistentStore.  SQLite error code:14, 'unable to open database file'";
  })
  </code></pre>
  
  <p>I did find this article on Apple's website, which suggests a potential <em>source</em> of the issue: <a href="https://developer.apple.com/library/ios/qa/qa1809/_index.html" rel="nofollow">https://developer.apple.com/library/ios/qa/qa1809/_index.html</a>  But it doesn't seem to help with my problem.  (It describes a way to migrate a persistent store and change the journaling options... but it assumes I already have an instance of NSPersistentStore, which I don't.  I could add it via the PSC... but that would require migrating it, which defeats the whole purpose--again, because I'm trying to find the version of the existing store before I migrate it.)</p>
  
  <p>One potential complication here is that I'm trying to switch from a UIManagedDocument store to a traditional CoreData stack (we're ditching UIManagedDocument because of a never-ending string of problems, and we understand a standard CoreData stack much better).  In practice this hasn't seemed to have been a problem (until now?) but I thought it might be worth mentioning.</p>
  
  <p>Edit: this is on an iPad (3rd generation) running iOS 7.1.1.</p>