Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData: error: (14) I/O error for database

When compiling and running in the XCode a project using Core Data I'm getting an error I never saw before:

 2013-09-12 16:59:10.156 myapp[57811:70b] CoreData: error: 
      (14) I/O error for database at /Users/administrador/Library/
         Application Support/iPhone Simulator/7.0/Applications/
         6BA67336-B093-46CF-8B11-E3595409DAC2/myapp.app/database.sqlite.  

         SQLite error code:14, 'unable to open database file'

The code that generates this message is:

    psc = [[NSPersistentStoreCoordinator alloc]
                   initWithManagedObjectModel:self.managedObjectModel];
    NSURL *storeURL = [[NSBundle mainBundle] 
                         URLForResource:@"database" withExtension:@"sqlite"];
    [psc addPersistentStoreWithType:NSSQLiteStoreType 
             configuration:nil URL:storeURL 
             options:@{NSReadOnlyPersistentStoreOption : @YES} error:NULL];

I have tried Build->Clean, remove derived data, uninstall the app.

I have checked this question before posting and I believe the problem is different.

Note: The sqlite is a resource of the app

The info using the debug suggested

2013-09-12 17:43:38.341 myapp[58322:70b] CoreData: annotation: Connecting to sqlite database file at "/Users/administrador/Library/Application Support/iPhone Simulator/7.0/Applications/6BA67336-B093-46CF-8B11-E3595409DAC2/myapp.app/database.sqlite"
2013-09-12 17:43:38.360 myapp[58322:70b] CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA
2013-09-12 17:43:38.363 myapp[58322:70b] CoreData: annotation: Disconnecting from sqlite database due to an error.
2013-09-12 17:43:38.364 myapp[58322:70b] CoreData: error: (14) I/O error for database at /Users/administrador/Library/Application Support/iPhone Simulator/7.0/Applications/6BA67336-B093-46CF-8B11-E3595409DAC2/myapp.app/database.sqlite.  SQLite error code:14, 'unable to open database file'
2013-09-12 17:43:38.366 myapp[58322:70b] CoreData: annotation: Disconnecting from sqlite database.
like image 262
ppaulojr Avatar asked Sep 12 '13 20:09

ppaulojr


People also ask

What database does Coredata use?

Core Data can use SQLite as its persistent store, but the framework itself is not a database. Core Data is not a database. Core Data is a framework for managing an object graph.

Is Coredata a relational database?

Core Data is not a relational database or a relational database management system. It can use SQLite as one of its persistent store types, but it is not in and of itself a database. You could set up Core Data to just use an in-memory store just to get the change tracking and management features without persistence.

Where is Coredata stored?

The persistent store should be located in the AppData > Library > Application Support directory.

Is Coredata a framework?

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.


Video Answer


1 Answers

Now that the NDA on iOS7 has been lifted I can post for the sake of completion the workaround I found for this problem.

The Core Data in iOS7 uses by default WAL in the sqlite.

The only solution that did work was to create the sqlite using iOS6 simulator without WAL and import it in the project:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    static NSPersistentStoreCoordinator *psc;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        psc = [[NSPersistentStoreCoordinator alloc] 
                 initWithManagedObjectModel:self.managedObjectModel];
        NSURL *storeURL = [[NSBundle mainBundle] 
                  URLForResource:@"database" withExtension:@"sqlite"];
        [psc addPersistentStoreWithType:NSSQLiteStoreType
                          configuration:nil
                                    URL:storeURL
                                options:@{NSReadOnlyPersistentStoreOption : @YES,
                             NSSQLitePragmasOption: @{@"journal_mode":@"DELETE"}}
                                  error:NULL];
    });
    return psc;
}
like image 56
ppaulojr Avatar answered Oct 20 '22 20:10

ppaulojr