2012-09-18 30 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忽略。

相關問題