2015-01-26 89 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(); 
}