2012-09-18 29 views
0

我正在构建应用程序的原型,其中持久存储通过AFP在“服务器”计算机(同一LAN)上使用SQLite。 但是,我无法连接到我的应用程序的2个不同实例的商店。将核心数据持久存储(SQLite)设置为NORMAL锁定模式

我设置持久存储协调SQLite的编译设置(与锁)是这样的:试图即当第一次连接到从第二个客户端存储(当

NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom]; 

NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary]; 
[pragmaOptions setObject:@"NORMAL" forKey:@"locking_mode"]; 
NSDictionary *storeOptions = [NSDictionary dictionaryWithObject:pragmaOptions forKey:NSSQLitePragmasOption]; 

if (![coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:storeOptions error:&error]) { 
    [[NSApplication sharedApplication] presentError:error]; 
    return nil; 
} 

和错误消息我得到一个已经成功连接)是:

ERROR: sqlite database is locked because it is in use by another host that holds a host-exclusive lock on .../TestDBApp.storedata; this host UID... cannot override the host-exclusive lock until the other host UID... releases its locks on .../.TestDBApp.storedata-conch

我做错了什么?

是否正在使用Core Data和SQLite从2个客户端访问相同的存储?

这是Core Data和/或SQLite API中的错误吗?

回答

0

SQLite不允许数据库文件具有多个写入锁定。对任何更改数据的事务,或应用程序明确请求的事务都采用写入锁定。

显然,核心数据连接持有写入事务或写入锁定打开。

0

据我记忆,核心数据将使用独占锁定模式的保存方法。我建议你将参数“-com.apple.CoreData.SQLDebug 1”传递给你的应用程序。如果您在控制台中发现“BEGIN EXCLUSIVE”,我想您的设置将被Core Data忽略。

相关问题