2015-01-26 92 views
0

我正在使用MvvmCross創建Android,WPF和Windows Phone 8/8.1應用程序。我已經在WPF和Android應用程序中正常使用SQLite。MvvmCross - Windows Phone 8 + SQLite - 無法打開數據庫文件

使用Windows Phone應用程序時,我在調用SQLite數據庫文件的Create()時遇到了問題。

第一次調用時,創建和打開工作就好了,但是當第二次調用create()時,它總是失敗。

代碼:

ISQLiteConnection db = factory.Create("filename.sql"); 
db.Close(); 

錯誤:

"Could not open database file: filename.sql (CannotOpen)" 

堆棧:

at SQLite.SQLiteConnection..ctor(String databasePath, Boolean storeDateTimeAsTicks) 
at Cirrious.MvvmCross.Plugins.Sqlite.WindowsPhone.MvxWindowsPhoneSQLiteConnectionFactory.Create(String address) 
at MvvmCrossPOC.Core.Services.MetadataService.OpenDatabase() 

我跟着這篇文章,並用類似的步驟等,並增加了MvvmCross SQLite的插件(V3 .5 - 安裝包MvvmCross.HotTuna.Plugin.SQLite),但錯誤依然存在。

WP8 SQLite error: The specified module could not be found

就如何推進有什麼想法?

代碼示例:

public MetadataService(ISQLiteConnectionFactory SQLiteConnectionFactory) 
{ 
    factory = SQLiteConnectionFactory; 
} 

public List<Platform> GetPlatformCollection() 
{ 
    db = factory.Create(METADATA_REPO_NAME); 
    try 
    { 
     return db.Table<Platform>().ToList(); 
    } 
    finally 
    { 
     db.Close(); 
    } 
} 

回答

1

精氨酸!小時來弄清楚這一切都是我寫錯了代碼。

記住:服務是單身...所以,你不必在每次使用它時打開和關閉數據庫!

想通了這一點找到斯圖爾特的SQLite的例子後:KittensDB

不知道爲什麼,我沒有看到任何其他平臺這個問題...

工作代碼示例

public MetadataService(ISQLiteConnectionFactory factory) 
{ 
    //Get the connection 
    db = factory.Create(METADATA_REPO_NAME); 

    db.CreateTable<PlatformStorage>(); 
    db.CreateTable<DashboardStorage>(); 
} 

public List<Platform> GetPlatformCollection() 
{ 
    return db.Table<Platform>().ToList(); 
}