CoreData:error:(14)数据库的I / O错误 [英] CoreData: error: (14) I/O error for database

查看:227
本文介绍了CoreData:error:(14)数据库的I / O错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在XCode中编译和运行使用 Core Data 的项目时,我遇到了以前从未见过的错误:


$ b $发布时间:15年07月12日原作者:dcow 3 0数据库的I / O错误/ Users / administrators /
应用程序支持/ iPhone模拟器/ 7.0 /应用程序/
6BA67336-B093-46CF-8B11-E3595409DAC2 / myapp.app / database.sqlite。

SQLite错误代码:14,'无法打开数据库文件'

生成此消息的代码是:

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

我尝试过 Build-> Clean ,删除衍生数据,卸载应用程序。



我已选中

注意: > sqlite是应用程序的资源



使用调试建议的信息

 <$ c / c / c / c / c / c / c / c / c / c / c / c ++ / c / c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c ++ c# 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:注释:由于错误而断开与sqlite数据库的连接。
2013-09-12 17:43:38.364 myapp [58322:70b] CoreData:error:(14)数据库的I / O错误/ Users / administrador / Library / Application Support / iPhone Simulator / 7.0 / /6BA67336-B093-46CF-8B11-E3595409DAC2/myapp.app/database.sqlite。 SQLite错误代码:14,'无法打开数据库文件'
2013-09-12 17:43:38.366 myapp [58322:70b] CoreData:注释:断开与sqlite数据库的连接。


解决方案

现在iOS7上的NDA已经解除



iOS7中的Core Data默认使用 WAL sqlite



唯一的解决方案是使用iOS6模拟器创建sqlite, c $ c> WAL 并将其导入项目:

   - (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{
static NSPersistentStoreCoordinator * psc;
static dispatch_once_t onceToken;
dispatch_once(& onceToken,^ {
psc = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:self.managedObjectModel];
NSURL * storeURL = [[NSBundle mainBundle]
URLForResource:@databasewithExtension:@sqlite];
[psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:@ {NSReadOnlyPersistentStoreOption:@YES ,
NSSQLitePragmasOption:@ {@journal_mode:@DELETE}}
error:NULL];
});
return psc;
}


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.

解决方案

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;
}

这篇关于CoreData:error:(14)数据库的I / O错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆