我正在使用SQLite for Windows Phone 7(http://sqlitewindowsphone.codeplex.com/),並且我已經完成了本教程中的每一個步驟(http://然後,我嘗試做一些簡單的應用程序的基本功能,如像選擇並刪除。應用程序正常工作,直到我想進行這項操作之一。當我點擊選擇或刪除,編譯器顯示我錯誤,他無法打開數據庫文件...「無法打開數據庫文件」在Windows Phone 7上使用SQLite
我不知道爲什麼?
我正在使用SQLite for Windows Phone 7(http://sqlitewindowsphone.codeplex.com/),並且我已經完成了本教程中的每一個步驟(http://然後,我嘗試做一些簡單的應用程序的基本功能,如像選擇並刪除。應用程序正常工作,直到我想進行這項操作之一。當我點擊選擇或刪除,編譯器顯示我錯誤,他無法打開數據庫文件...「無法打開數據庫文件」在Windows Phone 7上使用SQLite
我不知道爲什麼?
您確定該文件存在? 您可以檢查這樣的:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
exists = store.FileExists(DbfileName);
}
我用同樣的SQLite的客戶端,並有同樣的問題。發生此問題是因爲sqlite嘗試在IsolatedFileStorage「DatabaseName.sqlite-journal」中創建文件,並且它沒有足夠的權限。我解決了這個問題,因此在將數據庫複製到IsolatedFileStorage之前創建了「DatabaseName.sqlite-journal」。這是我做的方法:
private void CopyFromContentToStorage(String assemblyName, String dbName)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
string uri = dbName + "-journal";
store.CreateFile(uri);
using (Stream input = Application.GetResourceStream(new Uri("/" + assemblyName + ";component/" + dbName,UriKind.Relative)).Stream)
{
IsolatedStorageFileStream dest = new IsolatedStorageFileStream(dbName, FileMode.OpenOrCreate, FileAccess.Write, store);
input.Position = 0;
CopyStream(input, dest);
dest.Flush();
dest.Close();
dest.Dispose();
}
}
它幫助了我,並且運作良好。
希望這會幫助你
你是什麼意思,通過編譯器顯示你的錯誤?你的意思是該計劃呢? – thumbmunkeys 2011-04-25 18:46:03
我是WP7的初學者,所以我添加了這個屏幕。 [鏈接] https://picasaweb.google.com/lh/photo/g09-xLru6B0WVF3QcWPgiQ?feat=directlink [/鏈接]它出現後,我嘗試使用刪除功能按鈕 – dargod 2011-04-25 18:59:43
檢查是否存在數據庫文件,因爲我解釋該職位。如果這沒有幫助,我會通過插入數據填充數據庫中的數據(而不是使用外部程序) – thumbmunkeys 2011-04-25 19:11:40