2

In my cocoa application, i am using core data to maintain all my datas. But some time ,i am getting the below given issue.

Issue:

CoreData: error: (14) I/O error for database at /Users/my-mac/Documents/FileT.sqlite.  SQLite error code:14, 'unable to open database file'

Here i given the code reference for persistentStoreCoordinator :

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }



    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory]
                                               stringByAppendingPathComponent: @"FileT.sqlite"]];

    NSError *error = nil;
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
                                   initWithManagedObjectModel:[self managedObjectModel]];
    options = @{
                NSMigratePersistentStoresAutomaticallyOption : @YES,
                NSInferMappingModelAutomaticallyOption : @YES
                };


    if(![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                                  configuration:nil URL:storeUrl options:options error:&error]) {
        /*Error for store creation should be handled in here*/
    }

    return _persistentStoreCoordinator;

}

Can anyone suggest what i am missing here?

2
  • Can you describe "some time" a little more? Does this happen randomly, or only on certain devices, or what? Commented Jul 23, 2014 at 2:34
  • @TomHarrington It happens randomly, not at particular device/instance. when i try to retrieve/insert my data , it will happen at random instance not all the time. Commented Jul 23, 2014 at 5:15

1 Answer 1

3
+50

Take a look at Technical Q&A 1809: New default journaling mode for Core Data SQLite stores in iOS 7 and OS X Mavericks

Your application may be moving or changing the WAL journal files or SQLite files, or may have made assumptions about the file structure that was valid for versions of Core Data that did not use WAL.

It's also possible that your SQLite database is being corrupted, and the error 14 is SQLite attempting to repair the file when Core Data opens it. This corruption can happen if the application was not shut down properly when a write was happening - and many other circumstances. Not shutting down properly is the most common case on Apple platforms though - for example, if Core Data is writing records and the OS kills the application because it's unresponsive. That can cause corruption.

Sign up to request clarification or add additional context in comments.

3 Comments

I haven't received any sqlite error message until now in my QA testing. Thanks.
I've been trying to replicate something similar for a bug report - forcing the sqlite db into recovery mode before it's opened.
I have a Mac app that converts data into a Core Data SQL store, which is then copied over to iOS. Since upgrading my Mac to Yosemite, I'm having this issue, and the technical Q&A you linked provided the right solution of migrating instead of copying. Many thanks, @quellish!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.